GitXplorerGitXplorer
s

ajax-interceptor

public
120 stars
22 forks
1 issues

Commits

List of commits on branch master.
Verified
a262e7d2f89e55364e3062812af8b775295835b7

Update README.md

sslorber committed 6 years ago
Unverified
898f054eef120ecf83e910806bbacbd27aeb6623

add isWired() method

sslorber committed 8 years ago
Unverified
4bc5507a25b7be91ef6d1d63fdbaa040c2945154

Update README.md

sslorber committed 10 years ago
Unverified
02beddd06cf0dfb7fc0e79ccd66612393987a4cb

Update README.md

sslorber committed 10 years ago
Unverified
25eacda9e5a91ce06940ff21bc95eddf5986a1e3

Update README.md

sslorber committed 10 years ago
Unverified
95b3647afce98f8b52d92b23fbd900768e9b3179

Update README.md

sslorber committed 10 years ago

README

The README file for this repository.

ajax-interceptor

This permits to wire some request and response hooks on any Ajax calls.

I find this handy, for exemple, to handle user session expiration and redirect the user to the login page whenever an Ajax call fails with an auth failure.

Install

Install it!

npm install ajax-interceptor --save

Use it! (with Browserify)

var AjaxInterceptor = require("ajax-interceptor");

No other support for now, but feel free to contribute.

API

// Setup some callbacks
AjaxInterceptor.addRequestCallback(function(xhr) {
    console.debug("request",xhr);
});
AjaxInterceptor.addResponseCallback(function(xhr) {
    console.debug("response",xhr);
});

// Will proxify XHR to fire the above callbacks
AjaxInterceptor.wire();

// Do some requests
// ................

// Will restore XHR and not fire anymore the callbacks
AjaxInterceptor.unwire();

You can add and remove callbacks dynamically while the interceptor is wired.

Alternatives

If you just want to be able to intercept JQuery $.ajax() calls, Global Ajax Event Handlers also work.

License

MIT

Hire a freelance expert

Looking for a React/ReactNative freelance expert with more than 5 years production experience? Contact me from my website or with Twitter.