admin管理员组文章数量:1326447
I am trying to find out what parameters I can pass to a jQuery ajax call.
What I am used to is writing something like:
$.ajax({
....
success: function(response) {
// put callback here
}
....
});
So here is my question:
Obviously the "response" variable I put in the success function just takes back whatever the server sends back from the ajax call. Is there any possible way to send multiple variables back? Something like:
...
success: function(response,httpStatus,whateverElse) {
}
...
Or, is there some other way to get the http response codes?
Thanks to whoever can answer this!
I am trying to find out what parameters I can pass to a jQuery ajax call.
What I am used to is writing something like:
$.ajax({
....
success: function(response) {
// put callback here
}
....
});
So here is my question:
Obviously the "response" variable I put in the success function just takes back whatever the server sends back from the ajax call. Is there any possible way to send multiple variables back? Something like:
...
success: function(response,httpStatus,whateverElse) {
}
...
Or, is there some other way to get the http response codes?
Thanks to whoever can answer this!
Share Improve this question asked Jan 30, 2015 at 1:38 Walker FarrowWalker Farrow 3,9249 gold badges36 silver badges56 bronze badges4 Answers
Reset to default 5You can get the response
's status code
on the success'
third parameter or plete
's first parameter, something like this:
$.ajax({
success: function(data, textStatus, xhr) {
console.log(xhr.status);
},
plete: function(xhr, textStatus) {
console.log(xhr.status);
}
});
Further to @Kokizzu you can check the jQuery API site to see what parameters are passed to the other functions http://api.jquery./jquery.ajax/.
Also another way that I find handy to work out what parameters are being passed when there are no docs available is:
success: function() {
console.log(arguments);
}
That will log to the console all of the arguments that were passed to that function when it was called.
You can also have the server send back json json_encode
in php:
Php:
$array['status'] = 0;
$array['foo'] = 'bar';
json_encode($array);
Ajax:
$.ajax({
...
success: function (data) {
console.log(data);
}
});
Then obviously you could have your callback handle those variables.
$.ajax({
success: function(data, status, xhttp) {
console.log(status + ": " + data);
},
error: function(data, status, xhttp) {
console.log(status + ": " + data);
}
});
本文标签: javascriptparameters in jquery ajax successStack Overflow
版权声明:本文标题:javascript - parameters in jquery ajax success - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742213707a2434179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论