https://github.com/gdibble/backbone-ajaxretry
Exponentially retry Backbone.ajax & $.ajax requests
https://github.com/gdibble/backbone-ajaxretry
Last synced: about 1 year ago
JSON representation
Exponentially retry Backbone.ajax & $.ajax requests
- Host: GitHub
- URL: https://github.com/gdibble/backbone-ajaxretry
- Owner: gdibble
- License: mit
- Created: 2014-04-05T00:05:11.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-06-01T10:37:12.000Z (about 11 years ago)
- Last Synced: 2024-11-02T17:07:40.554Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 262 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Backbone.js ajaxRetry
#### Exponentially retry Backbone.ajax and $.ajax requests
## Installation
```
npm install --save backbone-ajaxretry
```
In your client app `main.js`, add the following line to default retry settings:
```javascript
require('backbone-ajaxretry');
```
Or override any of the default settings using `set`: passing keyword arguments
```javascript
require('backbone-ajaxretry').set({ y:0.3 });
```
## Usage
The default settings are:
```javascript
{
base: 2.718281828,
y: 0.25,
retryCount: 3,
onlyBackbone: false
}
```
By default both `Backbone.ajax` and `$.ajax` [Server Errors](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error) are retried. To only retry `Backbone.ajax` requests and not also [regular] `$.ajax` requests, change the `onlyBackbone` default setting to `true`.
For Backbone.js sync, fetch, save or destroy, pass `exhaust` in the options object as a callback function to run when retries fail
* please note that `exhaust` supersedes the `error` callback
* if `exhaust` method is not passed, retries will end without further action
* the returned `jqXHR` object has been extended with the ajax request options,
thus allowing `jqXHR.type`, `jqXHR.url`, etcetera
```javascript
// Backbone ex.
myModel.fetch({
exhaust : function (jqXHR, textStatus, errorThrown) {
// Handle Internal Server Error
}
});
// $.ajax ex.
$.ajax({
url: '/test',
type: 'GET',
exhaust : function (jqXHR, textStatus, errorThrown) {
// Handle Internal Server Error
}
});
```
---
* **Changelog >>>** [releases](https://github.com/gdibble/backbone-ajaxretry/releases)
---
* **Dependency:** [Underscore.js](http://underscorejs.org/)
* ***Implied:***
* [Backbone.js](http://backbonejs.org)
* [jQuery](http://jquery.com), [zepto.js](http://zeptojs.com), [ENDER](http://ender.jit.su) **or** even your own `$` library *which defines `$.ajax`*
---
* [npmjs.org/package/backbone-ajaxretry](https://www.npmjs.org/package/backbone-ajaxretry)