SimpleAjax.js
SimpleAjax.js
- vanilla JavaScript library, which designed to make simple ajax-requests
Usage
// GET request to specified URL without parameters; // or; // HTMLFormElement (<form>) could be a single argument// if it has an `action` attribute, which will be used as `url`.// Its `method` attribute will be used as `method`. ; // or; // or just;
Options
url
(string) - requested resource's urlmethod
(ortype
) (string) - request method (GET
,POST
,HEAD
etc)data
(orcontent
) (object | HTMLFormElement | string) - object, form (or its selector)success
(function(AjaxResult)) - callback on successful request completionerror
(function(AjaxResult)) - callback on request failurestatusCode
(object) - an object of numeric HTTP codes and functions to be called when the response has the corresponding codeheaders
(object) - dictionary of request headersbeforeSend
(function(XMLHttpRequest)) - function for modifying a request before sending itbeforeReturn
(function(AjaxResult, XMLHttpRequest)) - function for modifying a response before returning itmodifier
(object) - object with propertiesbeforeSend
or/andbeforeReturn
(works the same as the functions above)
AjaxResult
response
value
(object) -Object
containing the response to the request, or null if the request was unsuccessful or it can't be parsed as JSONdocument
(document) -Document
containing the response to the request, or null if the request was unsuccessful or it can't be parsed as XML or HTMLtext
(string) -DOMString
that contains the response to the request as texturl
(string) - serializedURL
of the response or the empty string if the URL is nulltype
(string) - value that defines the response typestatus
(number) - unsigned short with the status of the response of the requeststatusText
(string) -DOMString
containing the response string returned by the HTTP serverhasError
(boolean) -true
if server returned an error codeheaders
(object) - dictionary of response headers
Examples
;
;
let response = await ;console;
Install
Via npm:
npm i simple-ajax-vanilla
Via JSDelivr:
Manually:
Simply download simpleAjax.min.js
from the latest release and add it to your project