jquery Ajax Synchronous asynchronous execution sample code (1/2)

Source: Internet
Author: User

function getreturnajax{
$.ajax ({
Type: "Post",
http://www.111cn.net/userexist.asp Tutorial X ",
Data: "Username=" +vusername.value,
Success:function (msg) {
if (msg== "OK") {
Showtipex (Vusername.id, "<b><font color= ' #ffff00 ') > The username can be used </font ></b> ", false)
return true;
}
Else
{
Showtipex (Vusername.id, "<b><font color= ' #ffff00 ') > The user has been registered </ Font></b> ", false);
Vusername.classname= "Bigwrong";
return false;
}
}
});
}

But we call this getreturnajax () always get false, that is to say return True,return false does not work at all, in Firefox under the Firebug debugging also proved that the code will not be executed to the return section.

What if we just try to define a variable in a function, then assign it in Ajax, and finally return the variable at the end of the function? We modified the code as follows:
Code
Copy code code as follows:
function Getajaxreturn ()
{
var Bol=false;
$.ajax ({
Type: "Post",
http://www.111cn.net/userexist.asp Tutorial X ",
Data: "Username=" +vusername.value,
Success:function (msg) {
if (msg== "OK") {
Showtipex (Vusername.id, "<b><font color= ' #ffff00 ') > The username can be used </font ></b> ", false)
return true;
Bol=true;
}
Else
{
Showtipex (Vusername.id, "<b><font color= ' #ffff00 ') > The user has been registered </ Font></b> ", false);
Vusername.classname= "Bigwrong";
return false;
}
}
});
return BOL;
}

Home 1 2 last page
Related Article

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.