2015-10-22 68 views
-1

我有一種情況,我需要執行一個函數,但即使調用之後,警告也會阻止函數執行。所以我需要在confirm()之前執行llamadaEntrante();但不能使其工作,任何想法?函數執行後繼續執行ajax處理

下面是代碼:

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

}); 

回答

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

不工作:(仍然執行首先確認.. :( – GDedieu

+0

它不能達到 「確認(」 Tiene UNA llamada德「+陣列[0 ]);「除非llamadaEntrante()已經完成,否則沒有任何意義。」首先確認()「的含義是什麼???? – AdamJeffers

+0

無論誰做了投票,你能解釋一下嗎?這是一個完全合理的答案。 「問題提問」! – AdamJeffers