fabiocaccamo / xhrm.js

JavaScript XMLHttpRequest manager built on top of jQuery $.ajax.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xhrm.js

xml http request manager on top of jQuery $.ajax (all jQuery ajax options are supported)

Features:

  • Option baseURL (global): if defined all relative urls will be requested using the base url
  • Option overwrite: xhrm.overwrite.NONE (default), xhrm.overwrite.SAME_STATE, xhrm.overwrite.SAME_URL
  • Option state: '' used to overwrite concurrent requests for the same state
  • Option contentType accepts smart values: html, json, text, vars
  • Option dataType:'jquery' if you need to load a page as a jQuery object
  • Option timeout automatically detects if the value is in seconds or in milliseconds

APIs:

Class methods:

Config global options:

xhrm.configRequests({ baseURL:'http://localhost/' });

Create a request:

xhrm.createRequest({}); //return request object

Create and send a request:

xhrm.sendRequest({}); //return request object

Cancel a request by ID:

xhrm.cancelRequestByID(requestObj.id); //return request object

Cancel all requests:

xhrm.cancelAllRequests();

Instance methods/properties:

[property] String value of the request ID (auto-increment):

request.id;

[method] Boolean value that indicates if the request object has been sent

request.sent;

[method] Send the request object

request.send();

[property] Boolean value that indicates if the request object can be cancelled

request.cancelable;

[property] Boolean value that indicates if the request object has been cancelled

request.cancelled;

[method] Cancel the request object

request.cancel();

[method] Clone the request object

request.clone();

[method] String value that represent the request object

request.toString();

Example:

xhrm.sendRequest({
    url: '',
    overwrite: xhrm.overwrite.SAME_URL,
    contentType: 'html',
    dataType: 'jquery',
    timeout: 5, 
    success: function(element, text)
    {
        //console.log( element.find('body') );
    },
    error: function( error )
    {
        //console.log( error );
    }
});

License

Released under MIT License.

About

JavaScript XMLHttpRequest manager built on top of jQuery $.ajax.

License:MIT License


Languages

Language:JavaScript 100.0%