XHR
Back to Hell-licensed code
Download xhr.js (666 bytes)
It is a little to add in XMLHttpRequest "library". Native XMLHttpRequest is as simple as can be, most "enhancement" is just blackboxing the obvious.
What XHR does:
- it shortens XMLHttpRequest to XHR :-)
- it wraps XMLHttpRequest into Promise
- it can build encoded request string from JSON
Syntax
Promise XHR(string server[, object|string? get[, object|string? post[, fn? Pfn[, fn? Efn]]]])
- server URL of the server requested by HTTP(S)
- get data sent in URL
- post data sent in HTTP body
- Pfn(int loaded, int total, bool upload) if provided, it is called during the data transfer
- loaded number of bytes sent so far
- total total number of bytes to send
- upload true for upload phase (the request), false for download (the response)
- XMLHttpRequest Efn(XMLHttpRequest X) if provided, can enhance the XMLHttpRequest object before send
- object return the returned object in .then method receives an object with attributes
- string response the HTTP body of the response
- array headers the HTTP headers of the response