jquery对话框暂停一个类似alert()的脚本

时间:2013-12-02 16:18:42

标签: javascript jquery

我有下一个javascript代码:

function getLetterOfResponsibilityNote(dialogNoteLink, visitCountryName) {
        $.ajax({
            type: "GET",
            url: "/Admin/Applications/GetLetterOfResponsibilityNote/?selectedCountryName=" + visitCountryName,
            cache: false,
            success: function(data) {
                if (data != "") {
                    dialogNoteLink.dialog();
                    dialogNoteLink.attr("title", "Letter Of Responsibility Note for " + visitCountryName);
                    dialogNoteLink.html("<p>" + data + "</p>");
                }
            }
        });
    }

我想调用它,例如,5次从服务器获取数据,然后我将在对话框中显示它。但我得到一个带有消息的Jquery UI对话框。问题是当对话框打开时脚本不会暂停。

如果我写而不是它:

dialogNoteLink.dialog();
dialogNoteLink.attr("title", "Letter Of Responsibility Note for " + visitCountryName);
dialogNoteLink.html("<p>" + data + "</p>");

with alert() - 它工作正常!

我如何解决这个问题?

2 个答案:

答案 0 :(得分:3)

这就是JavaScript警报的工作原理。如果要调用等待对话框关闭,则必须在关闭对话框后在回调中进行后续调用。你应该这样做 -

var arrayofNotesAndCountryNames = [{
 "dialogNoteLink" : link1,
 "visitCountryName" : "country1"
},{
 "dialogNoteLink" : link2,
 "visitCountryName" : "country2"
},{
 "dialogNoteLink" : link3,
 "visitCountryName" : "country3"
}];    
var currentIndex = 0;

function getLetterOfResponsibilityNote() {
var dialogNoteLink = arrayofNotesAndCountryNames[currentIndex].dialogNoteLink;
var visitCountryName = arrayofNotesAndCountryNames[currentIndex].visitCountryName;
            $.ajax({
                type: "GET",
                url: "/Admin/Applications/GetLetterOfResponsibilityNote/?selectedCountryName=" + visitCountryName,
                cache: false,
                success: function(data) {
                    if (data != "") {
                        dialogNoteLink.dialog({close : function(){ 
                             currentIndex++;
                             if (currentIndex < arrayofNotesAndCountryNames.length){
                                  getLetterOfResponsibilityNote();
                             }

                        }

});
                        dialogNoteLink.attr("title", "Letter Of Responsibility Note for " + visitCountryName);
                        dialogNoteLink.html("<p>" + data + "</p>");
                    }
                }
            });
        }

getLetterOfResponsibilityNote();

答案 1 :(得分:0)

应该从查询回调到服务器来显示对话框。

JQuery上没有阻止功能或对话框。