I have a question about how the XMLHttpRequest object works. In https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest, under properties I am looking at the “response” property. The description says I should get a JavaScript object back if my content type is json. However, in my code the xhr.response property is undefined.
Specifically, I have a .ajaxSuccess() callback that is setup on a DOM element, it receives the parameters (event, xhr, settings). xhr.responseText is the plaintext version of my json, but xhr.response is undefined. Is there any way I can get the object from xhr without calling $.parseJson(xhr.responseText)?
I think you are confusing the
XMLHttpRequestobject with jQuery’sjqXHRobject used by$.ajaxSuccess(), which is supposed to be a superset of the former.Instead, you could use
$.ajax()‘sdonehandler, which will parse the JSON for you if the data type isjson. For example:Also note that even though the documentation of
$.ajaxSuccess()says that you get a vanillaXMLHttpRequestobject, that is no longer true as of jQuery 1.4.1. Instead, you get ajqXHRobject.