大家先看一段简单的jquery ajax 返回值的js
代码
function getReturnAjax{
$.ajax({
type:"POST",
http://www.cnblogs.com/wlmemail/admin/%22ajax/userexist.aspx",
data:"username="+vusername.value,
success:function(msg){
if(msg=="ok"){
showtipex(vusername.id,"
return true;
}
else
{
showtipex(vusername.id,"
vusername.className="bigwrong";
return false;
}
}
});
}
但是我们调用这个getReturnAjax()发现始终取得的都是false,那就是说return true,returnfalse根本没有起作用,在火狐下用firebug调试也证明,代码根本不会执行到return 部分。
代码
function getAjaxReturn()
{
var bol=false;
$.ajax({
type:"POST",
http://www.cnblogs.com/wlmemail/admin/%22ajax/userexist.aspx",
data:"username="+vusername.value,
success:function(msg){
if(msg=="ok"){
showtipex(vusername.id,"
// return true;
bol=true;
}
else
{
showtipex(vusername.id,"
vusername.className="bigwrong";
//return false;
}
}
});
return bol;
}
结果仍然不起作用。最后解决方案有2,如下
代码
function getAjaxReturn()
{
var bol=false;
$.ajax({
type:"POST",
async:false,
http://www.cnblogs.com/wlmemail/admin/%22ajax/userexist.aspx",
data:"username="+vusername.value,
success:function(msg){
if(msg=="ok"){
showtipex(vusername.id,"
// return true;
bol=true;
}
else
{
showtipex(vusername.id,"
vusername.className="bigwrong";
//return false;
}
}
});
return bol;
}