6

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

只需显示一个对话框,其中包含“请稍候...”消息,而我正在执行 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
}
4

2 回答 2

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);
        }
    });
} 
于 2013-04-04T19:12:10.613 回答
0

有了这个评论

  `As I described my problem, in fact I would like to first display the dialog: $("#myDialogBox").dialog();` 

And after call the ajax..

解决方案是:

从点击按钮id="btn"

$( "#btn_Deletepara" ).click(function() {
                $( "#JQUERY'sDialog" ).dialog( "open" );
//Now you Call the ajax
            });

或者

$( "#JQUERY'sDialog" ).dialog({

Add your script for call ajax
于 2013-04-04T16:51:42.963 回答