函数执行后继续ajax处理

Continue ajax processing after function execute

本文关键字:ajax 处理 继续 执行 函数      更新时间:2023-09-26

我有一种情况,我需要执行一个函数,但警报阻止函数执行,即使它在调用之后。所以我需要llamadaEntrante()confirm()之前执行;但却行不通,有什么想法吗?

代码如下:

$.ajax({
    type: "GET",
    data: {func: 'checkLlamadaEntrante'},
    url: 'https://www.cge.mil.ar/adm_sis/pedirLlamada.aspx'
})
.done(function (data) {
    if (data != 0){
        llamadaEntrante();
        var array = data.split(',');
        conf_id = array[1];
        enEsperaDeConfirmacion(conf_id);
        var r = confirm("Tiene una llamada de "+array[0]);
        if (r == true) {
            aceptaLlamada(conf_id);
            $("#videoLlamada_container").children('iframe').remove();
            $("#videoLlamada_container").show('slow');
            $("#videoLlamada_container").children('div.buscardor_grilla').children('input:first').focus();
            $("#videoLlamada_container").append('<iframe src="https://www.cge.mil.ar/videollamadaapp/default.aspx?conf_id='+conf_id+'" height="410px" width="534px" scroll="no"></iframe>');
            $("#option_aux").hide();
        } else {
            cancelaLlamada(conf_id);
        }
        cortaEntrante();
    } else {
        console.info('no llamaron');
    }
});

我想这应该行得通…你知道什么是承诺吗?

function llamadaEntrante()
{
    return new Promise(function(resolve, reject){
        // put your normal llamadaEntrante code in here
        // doing some stuff
        // and then resolve the promise with just true in this case
        resolve(true);
    });
}

所以只是澄清一下…

$.ajax({
        type: "GET",
        data: {func: 'checkLlamadaEntrante'},
        url: 'https://www.cge.mil.ar/adm_sis/pedirLlamada.aspx'
    })
    .done(function (data) {
        if (data != 0)
        {
            llamadaEntrante()
            .then(function()
            {
                var array = data.split(',');
                conf_id = array[1];
                enEsperaDeConfirmacion(conf_id);
                var r = confirm("Tiene una llamada de "+array[0]);
                if (r == true) 
                {
                    aceptaLlamada(conf_id);
                    $("#videoLlamada_container").children('iframe').remove();
                    $("#videoLlamada_container").show('slow');
                    $("#videoLlamada_container").children('div.buscardor_grilla').children('input:first').focus();
                    $("#videoLlamada_container").append('<iframe src="https://www.cge.mil.ar/videollamadaapp/default.aspx?conf_id='+conf_id+'" height="410px" width="534px" scroll="no"></iframe>');
                    $("#option_aux").hide();
                } else 
                    cancelaLlamada(conf_id);
                cortaEntrante();
            });
        }else{
            console.info('no llamaron');
        }
    });