easy-ajax
v1.1.0
Published
Simple wrapper functions for XMLHttpRequest.
Downloads
369
Maintainers
Readme
easy-ajax
Simple wrapper functions for XMLHttpRequest.
Installation
npm install easy-ajax
Usage
var ajax = require("easy-ajax");
var requestObject = ajax(method, url, options, then);
var requestObject = ajax(method, url, then);
var requestObject = ajax.get(url, options, then);
var requestObject = ajax.get(url, then);
var requestObject = ajax.post(url, data, options, then);
var requestObject = ajax.post(url, data, then);
requestObject
: XMLHttpRequest instance.method
: HTTP method: "GET", "POST", ...options
: Configuration object:timeout
: Timeout in ms.data
: Data to send (when POSTing).randomize
: Add a random query string to prevent caching?before
: A function to call after opening and before sending the request; called with the XMLHttpRequest object as the first argument.headers
: A hash object with additional headers to set; the keys are the header names, the values the values to set for the header.
then
: Callback for when the request is finished.
function then (error, requestObject) { /* ... */ }
error
: AnError
instance ornull
when there are no errors.requestObject
: The finishedXMLHttpRequest
instance.