jquery-ajaxreadystate

readystatechange events in jQuery AJAX.

jquery-ajaxreadystate was developed out of a necessity to access the response headers from an AJAX request before the transfer is completed. Vanilla JS proponents would be quick to say “just create your own XHR object,” and while they do have a point, jQuery’s AJAX wrapper provides many powerful features and is invaluable for legacy browser support.

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, since done, fail, always, and statusCode 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 below).

This plugin works by adding a new method jQuery.ajaxreadystate method, which acts as a wrapper for jQuery.ajax, extending the functionality and updating the jqXHR object to remove the limitations and update properties as the readyState changes.

 

Downloads

Download now or visit my GitHub repository.

Also available through NPM and Bower.