My latest open source contribution to the world is jquery-ajaxreadystate, a jQuery plugin which adds a new AJAX function with readystatechange
capabilities, available for download on GitHub, NPM, and Bower.
The jQuery AJAX implementation is somewhat limited in that it does not provide a way of responding to the readystatechange
events that fire during the AJAX request. The jQuery.ajax
API documentation actually states the following.
No
onreadystatechange
mechanism is provided, however, sincedone
,fail
,always
, andstatusCode
cover all conceivable requirements.
While this statement is true for most use cases, what if you want to access the response headers or status code before the entire request completes, or access the response body as it streams?
Evidently jQuery does not provide this functionality due to browser compatibility issues, so this plugin adds this extra functionality for browsers that support these features (see compatibility notes in the repo).
This plugin works by adding a new jQuery.ajaxreadystate
method, which acts as a wrapper for jQuery.ajax
, extending the functionality and updating the jqXHR
object to remove the limitations and updating properties as the readyState
changes.
Comments