xml http request manager on top of jQuery $.ajax
(all jQuery ajax options are supported)
- 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
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();
[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();
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 );
}
});
Released under MIT License.