如何获取Jquery.ajax成功函数的返回值
问题描述:
我有一些这样的代码
function doSomething(){
Jquery.ajax(type: "POST",
url: "HelloWorld",
success: function (msg) {
if(msg.d =="Hello World")
{
return true;
}else
{
return false;
}
}
);
}
我想了解一些成功函数返回值的基础. 有人可以帮忙吗?
i want to know something based on which the return value of the succes function. Can somebody help?
答
您不能.异步JavaScript和XML是异步.
You can't. Asynchronous JavaScript and XML is Asynchronous.
当HTTP请求返回时,回调函数将运行,届时doSomething
将完成执行.
The callback function will run when the HTTP request comes back, by which time doSomething
will have finished executing.
无论您希望响应HTTP响应而发生什么,都必须在回调函数中完成,而不是在任何称为回调的函数中完成.
Whatever you want to happen in response to the HTTP response returning has to be done in the callback function and not in whatever called it.