https://github.com/darfink/ajaxu
A tiny jQuery plugin for unique ajax requests
https://github.com/darfink/ajaxu
Last synced: 3 months ago
JSON representation
A tiny jQuery plugin for unique ajax requests
- Host: GitHub
- URL: https://github.com/darfink/ajaxu
- Owner: darfink
- License: mit
- Created: 2016-02-25T19:32:24.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-09T13:29:25.000Z (over 8 years ago)
- Last Synced: 2025-02-18T07:18:08.984Z (3 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AjaxU
## A jQuery plugin for making unique ajax requestsThis is a simple plugin provided for use cases where a request is supposed to
be unique. It does this by associating each request with a provided identifier.
If a request is issued whilst one with the same ID is already active, the first
request will be aborted and a new one will be created in its place.This behavior can also be changed, so that the first request will remain active
whilst the second one will be ignored (see the `abort` option).A common use case would be a `` element, where the user may click the
submit button multiple times, issuing several requests where only one is
required.## Usage
`$.ajaxu` follows the [$.ajax](http://api.jquery.com/jQuery.ajax/) options and return value, with an additional first parameter (the unique identifier).
```javascript
$.ajaxu(uid, opts);
````$.getu` follows the [$.get](http://api.jquery.com/jQuery.get/) options and return value, with an additional first parameter (the unique identifier).
```javascript
$.getu(uid, opts);
````$.postu` follows the [$.post](http://api.jquery.com/jQuery.post/) options and return value, with an extra first parameter (the unique identifier).
```javascript
$.postu(uid, opts);
````$.ajaxu.isRunning` returns a boolean representing if a request is currently running. `uid` is an optional parameter.
```javascript
$.ajaxu.isRunning(uid);
````$.ajaxu.getRequest` returns the active jqXHR request for the given identifier. `uid` is required.
```javascript
$.ajaxu.getRequest(uid);
````$.ajaxu.clear` removes any unprocessed requests. `uid` is an optional parameter.
```javascript
$.ajaxu.clear(uid);
````$.ajaxu.abort` aborts the current request. `uid` is required.
```javascript
$.ajaxu.abort(uid);
````$.ajaxu.defaults` defines the default options for `$.ajaxu`, where `abort` is true by default.
```javascript
$.ajaxu.defaults = { abort: true };
```