JQuery UI对话框显示等待消息,直到处理ajax调用

Zam*_*boo 5 jquery jquery-ui callback

我认为一切都在标题中.当我开始这个时,我认为这将是一个5分钟的代码或谷歌搜索时的快速结果...但现在是三个小时我在这:

只需显示一个对话框,其中包含"Please Wait ..."消息,而我正在执行ajax调用以检索一些json结果,然后显示"结果完成".

$('#switchOff').live("click",function(){

   $('#dialog').dialog({
                modal:true,

               open: function(){
// I would like to call myAjax function
//From here ?
// While my dialog is showing the Wait message...
               },


                complete: function(){
//close the dialog when fished
                 $('#dialog').dialog('close');
                         },
   }); 



});

function ajaxCall() {
                //my ajax call
}
Run Code Online (Sandbox Code Playgroud)

jmm*_*jmm 13

你不应该再使用live了.请.on改用.您正在混合对话框ajax代码.这是我将如何做的一个例子.

这里是演示小提琴的链接

$('#switchOff').on("click",  ajaxCall);

$("#loading").dialog({
    hide: 'slide',
    show: 'slide',
    autoOpen: false
});

function ajaxCall() {
    $.ajax({
        url: '/echo/html/',
        data: { html: '<p>JSON result</p>' , delay: 3},
        method: 'post',
        beforeSend: function(){
           $("#loading").dialog('open').html("<p>Please Wait...</p>");
        },
        success: function(data) {
            $('#loading').html("<p>Result Complete...</p>");
            $('#ajaxResult').html(data);
        }
    });
} 
Run Code Online (Sandbox Code Playgroud)