CUI.XHR is a wrapper around XMLHttpRequest and can be used for Ajax-Callbacks, as well as for loading files from and uploading files to a server.
The method used for the Request. This needs to be one of GET, POST, PUT, DELETE, or OPTIONS.
The url used for the Request.
Optionally, a user can be given. This is used for Basic HTTP Authentication.
Optionally, a password can be given. This is used for Basic HTTP Authentication.
The expected type of the response. Accepted are "", text, json, blob, arraybuffer. Defaults to json.
timeout is passed to the XMLHttpRequest, and is given in ms.
form is a PlainObject. new FormData() is used to build the body of the request.
url_data is a PlainObject. It can be used to pass parameters to be appended to the url.
body can be any data used as body for the request.
json_data is a PlainObject which JSON.stringified to be sent in the request body.
json_pretty is a Boolean which can be used to pretty print the JSON sent to the server if given by json_data.
headers is a PlainObject which can be used to set HTTP-Headers for the Request.
If set to true, the request is done with sending credentials. That usually means that Cookies are sent for Ajax-Requests.
Method to abort a running Request. This can be useful if CUI.XHR is used for uploading big files and the user decides to cancel the upload.
After creating the CUI.XHR, the request needs to be initiated, using start. This returns a CUI.Promise. The Promise is resolved if the request succeeds, rejected if it fails. During an upload, the Promise progresses and calls back notify.
Returns the current status of the CUI.XHR. There are the following possibilities:
The Status < 0 are CUI.XHR status, Status >= 0 are HTTP response status of the underlying XMLHttpRequest.
Returns the text of the current status.
Returns the ready state text of the underlying XMLHttpRequest.
Retrieve the response of the finished request.
Returns the underlying XMLHttpRequest instance.
Returns true, if the request is considered to be a success. States >= 200, < 300 and == 304 are considered to be a success. For files (using the file:///) URL, success is true if all ready states has been seen.
Returns a PlainObject of all response headers. The keys are lower cased, the values are inside an Array.
Returns the first item of the given key from the response headers.