Hello I have next function, what always return null as result, but service calling to success branch with any error, I would like to fix it: 1. Remove async attribute, 2. Other function that make GetStore function call should process result of this function. How I can do this in correct way ? ()
Thanks.
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;
}
});
}
If you want to make it asynchronous you can't wait for it to return a value, you have to implement callback functions.
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
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.