开发者

Access a variable declared in jquery ajax

开发者 https://www.devze.com 2023-03-16 14:20 出处:网络
I wanted to accessa 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

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

精彩评论

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