https://github.com/vstirbu/jquery-rest-observer
A simple jQuery plugin that adds REST observer support for ajax requests
https://github.com/vstirbu/jquery-rest-observer
Last synced: 7 months ago
JSON representation
A simple jQuery plugin that adds REST observer support for ajax requests
- Host: GitHub
- URL: https://github.com/vstirbu/jquery-rest-observer
- Owner: vstirbu
- License: mit
- Created: 2013-12-03T19:48:58.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-02-27T17:29:58.000Z (over 11 years ago)
- Last Synced: 2025-01-13T07:21:32.478Z (9 months ago)
- Language: JavaScript
- Size: 135 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A simple jQuery plugin that adds [REST observer](https://www.dropbox.com/s/adinujoywzdm9nc/chapter.pdf) support for ajax requests.
# Installation
Get the plugin using bower:
```bash
bower install https://github.com/vstirbu/jquery-rest-observer.git
```Include the script after jQuery library:
```html
```
# Usage
The plugin augments the built-in ajax interface with a new function ```observe```:
```javascript
$.ajax({
method: 'GET',
url: '/test'
}).observe().done(function () {
console.log('success');
}).fail(function () {
console.log('error');
});
```If the ```/test``` response includes a link header that conveys a ```monitor``` relationship with an observer resource
```
Link: ; rel="monitor"
```the plugin will perform the following actions:
* connect to the ```/observer```resource
* each time an update notification is delivered will make a request to ```/test```to fetch the latest state of the resource. On success will execute the callback provided to _done_, while on error will execute the callback provided to _fail_.When the method used for the ajax request is different than ```GET```, the user has the option to provide the done, fail and always callbacks as arguments of observe:
```javascript
$.ajax({
method: '{POST|PUT}'
...
}).observe(doneCallback, failCallback, alwaysCallback);
...
```# License
The code is available under MIT license.