https://github.com/slorber/ajax-interceptor
This permits to wire interceptors on XHR requests and responses
https://github.com/slorber/ajax-interceptor
Last synced: 8 months ago
JSON representation
This permits to wire interceptors on XHR requests and responses
- Host: GitHub
- URL: https://github.com/slorber/ajax-interceptor
- Owner: slorber
- License: mit
- Created: 2014-09-19T14:56:24.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-14T19:03:56.000Z (about 7 years ago)
- Last Synced: 2025-06-22T11:01:50.916Z (8 months ago)
- Language: JavaScript
- Homepage: https://sebastienlorber.com/
- Size: 4.88 KB
- Stars: 121
- Watchers: 4
- Forks: 22
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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**)
```javascript
var AjaxInterceptor = require("ajax-interceptor");
```
No other support for now, but feel free to contribute.
API
===============
```javascript
// 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](http://api.jquery.com/category/ajax/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](https://sebastienlorber.com/) or with [Twitter](https://twitter.com/sebastienlorber).