开发者

Access a variable declared in jquery ajax

I wanted to access a variable defined i开发者_Go百科n $.ajax({ outside the function . Inside ajax I have an if statement and else statement. If the control goes inside if, then after coming out from ajax function I need one function to run. So thinking of writing if outside ajax. Kindly let me know , if I can do like that?

success: function (msg) {
                if(msg.d == "No duplicate"){
             //code

                }
                else{
       //code
         }

After this, i write a confirm box which should be displayed only when it enters into if block.

 if (confirm("Are you sure you want to insert this new record ?") == false) {
                        hide();
                        return false;
                    }


If I understand correctly, it seems like you are trying to call a function, only if the ajax call succeeds, and some other condition (no duplicate) is met. It seems like it should be just as simple as calling this other function inside of your if statement:

function makeAjaxCall() {
    $.ajax({
        success: function(msg) {
            if (msg.d == "No duplicate") {
                doSomething();
            }
            else {
            }
        }
    });
}

function doSomething() {
    if (confirm(...)) {
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜