在Jquery Ajax中,我们可以获得响应值作为相应的函数返回值
checkSucess = function() {
// Jquery Ajax with url,params and response
doPost('sucess.php',
'first=' + first,
function(response) {
});
return response;// 'response' here is the value of response
如何返回函数的ajax响应值,该函数从其他函数
调用答案 0 :(得分:1)
当它是异步的时候,你不能按照你想要的方式去做 如果您确定请求不会持续很长时间,请将其设为异步:false并查看
checkSucess = function() {
var result;
//make it synchronus
$.ajaxSetup({async:false});
doPost('sucess.php',
'first=' + first,
function(response) {
//get the response
result = response;
});
//make it asynchronus
$.ajaxSetup({async:true});
return result;
}
答案 1 :(得分:0)
您可以定义一些全局变量并为其分配ajax响应:
var someGlobal; checkSucess = function() { // Jquery Ajax with url,params and response doPost('sucess.php', 'first=' + first, function(response) { someGlobal = response; }); return someGlobal;
这对你有用吗</ p>