【发布时间】:2016-01-03 23:45:13
【问题描述】:
我无法在 Jquery 中返回 ajax 请求的值。这是我的代码:
function ajaxUniversal(datos, url) {
$.ajax({
url: url,
data: {
valores: datos
},
type: "POST",
dataType: "html",
success: function (data) {
console.log("Datos recibidos: "+data)
return data; //This does not returns the data
},
error: function (errorThrown) {
return false;
}
});
}
如果我将 return 语句添加到最后:
function ajaxUniversal(datos, url) {
$.ajax({
url: url,
data: {
valores: datos
},
type: "POST",
dataType: "html",
success: function (data) {
console.log("Datos recibidos: "+data)
return data;
},
error: function (errorThrown) {
return false;
}
});
return data;//This is the statement but not works
}
我得到这个错误: 未捕获的 ReferenceError:未定义数据 如何返回数据?谢谢你。抱歉我的英语不好,但我会说西班牙语。
【问题讨论】:
-
你可以尝试添加 async:false 选项
标签: javascript jquery ajax methods return