函数执行

时间:2015-10-22 15:41:21

标签: javascript jquery ajax

我遇到这种情况,我需要执行一个函数,但警告会阻止函数执行,即使它在调用之后也是如此。所以我需要在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');
    }

});

1 个答案:

答案 0 :(得分:0)

我觉得这个shoudl工作......你对承诺一无所知吗?

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');
        }
    });