The problem of using return in success in the Ajax method of jquery

Source: Internet
Author: User

The Ajax method of jquery, the use of return in success, the end of the program, the end is only success this method, that is, success in the scope of return is only success;

If you want to use return to end the entire JS function in success, it is best to define a global variable in the outermost method body, var Isover = True, and Isover to False if the condition is met in success

In the Ajax method outside the body through the global variable Isover value to determine whether the JS function return,

At the same time also note: Ajax method Async:false, must be false;

function Mysubmit () {
Ajax verifies whether the current agent can initiate an application
var hasprivileage = true;
$.ajax ({
URL: "Commitcheckforagent.action",
Data: {agentno:$ ("#agentNo"). Val ()},
Type: "Post",
Async:false,
Success:function (Result) {
if (result = = "Billauditing") {
Alert ("The merchant has a billing change order that is being audited and cannot be launched again!") ");
hasprivileage = false;
return hasprivileage;
}
},
Error:function (Result) {
Alert (' Error ... ');
}
});
if (!hasprivileage) {
return;
   }
if ($ ("#agentNo"). Val () ==null | | $ ("#agentNo"). val () = = "") {
Alert ("Please enter the dealer number. ");
Return
}
if ($ ("#settleAccountType"). Val () ==null | | $ ("#settleAccountType"). val () = = "") {
Alert ("Account type cannot be empty.) ");
Return
}
if ($ ("#bankAccountName"). Val () ==null | | $ ("#bankAccountName"). val () = = "") {
Alert ("The bank account name cannot be empty.") ");
Return
}
if ($ ("#bankAccountNo"). Val () ==null | | $ ("#bankAccountNo"). val () = = "") {
Alert ("The bank account number cannot be empty.") ");
Return
}
if ($ ("#openBankName"). Val () ==null | | $ ("#openBankName"). val () = = "") {
Alert ("The name of the account bank cannot be empty. ");
Return
}
if ($ ("#province"). Val () ==null | | $ ("#province"). val () = = "") {
Alert ("The account-opening province cannot be empty. ");
Return
}
if ($ ("#city"). Val () ==null | | $ ("#city"). val () = = "") {
Alert ("The opening of the market cannot be empty. ");
Return
}
if ($ ("#file1"). Val () ==null | | $ ("#file1"). val () = = "") {
Alert ("Please upload the picture. ");
Return
}
var Customerno = $ ("#customerNo"). Val ()
$.ajax ({
Type: "Post",
Data:{customerno:customerno},
URL: "C005commitcheck.action",
Success:function (msg) {
if (msg = = "") {
$ ("#form1"). Submit ();
}else{
Alert (msg);
Window.location.href = window.location.href;
//      }
//     }
//    });
}

Using return in success in the Ajax method of jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.