[英]JQuery ajax return value to other function
你好我有下一个函数,什么总是返回null作为结果,但服务调用成功分支有任何错误,我想修复它:1。删除异步属性,2。使GetStore函数调用的其他函数应处理此结果功能。 我怎么能以正确的方式做到这一点? ()
谢谢。
function GetStore() {
$.ajax({
url: serviceurl + 'GetSometing',
type: 'POST',
contentType: 'application/json',
dataType: "json",
async: false,
success: function (result) {
return result;
},
error: function (xhr, description, error) {
return null;
}
});
}
如果你想使它异步,你不能等它返回一个值,你必须实现回调函数。
function GetStore(success, error) {
$.ajax({
url: serviceurl + 'GetSometing',
type: 'POST',
contentType: 'application/json',
dataType: "json",
success: success,
error: error
});
}
GetStore(function(result) {
// successful result
}, function(xhr, description, error) {
// an error occurred
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.