user2064000 user2064000 - 1 year ago 83
Ajax Question

How do I get the response text of an XHR in jQuery?

I have the following jQuery snippet:

$.get('/foo', 'a=foo&b=bar', function () {
// ...

The response object can be accessed by using
in the closure. However, I need to get the response text returned by the XHR. How do I go about doing this?

(BTW, since my use of "XHR" is apparently causing some confusion here, I'd like to clarify that this is not a XMLHttpRequest object but rather a jQuery object, which I've already verified.)

Answer Source

You rewrite the success-function like this:

$.get('/foo', 'a=foo&b=bar', function (data, textStatus, jqXHR) { 

For details, see

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download