Sunday, August 23, 2009

jXHR (JSON-P XHR)

jXHR is a clone-variant of the XMLHttpRequest object API, meaning it is (for the most part) API compatible. Some properties are not supported, such as responseText/XML/Body, and the request/response header functions are no-op's. Also, only "GET" is supported for the 'method' parameter of open(). And jXHR currently ignores any 'data' value passed to the send() function. All data you wish to send must be manually serialized into the 'url' parameter of open().

jXHR makes cross-domain JSON-P styled calls. The URL you pass to open() should have a parameter (usually named "callback") whose value is "?". The ? placeholder will be replaced by an internal callback created by jXHR. However, you can have the JSON-P data passed to your own callback handler by defining one for the "onreadystatechange" property of your jXHR instance.

Note: The "onreadystatechange" function will be called for all changes of readyState, like with normal XHR, so you need to filter it for readyState == 4 to handle the data object returned with the JSON-P call.

http://mulletxhr.com/

No comments: