new Ajax()
- Since:
-
- 1.0.0
Members
-
<static, constant> ALLOWED_METHODS
-
Provides an array of allowed HTTP methods.
- Since:
-
- 1.0.0
-
<static, constant> DEFAULT_ASYNC
-
Provides the default
asyncvalue for the Ajax calls.- Since:
-
- 1.0.0
-
<static, constant> DEFAULT_TIMEOUT
-
Provides the default
timeout(in milliseconds) for the Ajax calls.- Since:
-
- 1.0.0
-
<static, constant> XHRObject
-
Returns the Ajax object based upon the browser.
- Since:
-
- 1.0.0
Methods
-
<static> request(method, url, options)
-
Sends an HTTP request to a remote server and returns a Promise object. The Promise callback functions are passed the XMLHttpRequest object containing the response data. See XMLHttpRequest for details about accessing elements of the response.
Requests made by this method are by default asynchronous, and will return immediately. No data from the server will be available to the statement immediately following this call.
Example Usage:
mindsmine.Ajax.request( "GET", "valid URI", { headers: { "Accept" : "some value", "Content-Type" : "some value", "Authorization" : "some value" } } ).then((response) => { let responseJSON = JSON.parse(response.responseText); console.log(responseJSON); }).catch((response) => { console.log(`HTTP error code = ${response.status}`); }).finally(() => { console.log("This function is called regardless of success or failure."); });Parameters:
Name Type Description methodString The HTTP method to use for the request. Note that the method name is case-sensitive and should be all caps.
urlString The URL to which to send the request.
optionsObject An object which may contain the following properties:
Properties
Name Type Argument Default Description asyncBoolean <optional>
true trueif this request should run asynchronously.falseif this request should run synchronously (it will cause the UI to be blocked, the user won't be able to interact with the browser until the request completes).headersObject <optional>
Request headers to set for the request.
timeoutNumber <optional>
120000 The timeout is an unsigned long representing the number of milliseconds a request can take before automatically being terminated. Timeout should not be used for synchronous requests.
jsonDataObject | String <optional>
JSON data to be used in the request body.
withCredentialsBoolean <optional>
false The value for the withCredentials property of the XMLHttpRequest object.
beforeRequestfunction <optional>
The function to be called before a network request is made.
- Since:
-
- 1.0.0
Throws:
-
If invalid arguments.
- Type
- TypeError
Returns:
A Promise that resolves to an XMLHttpRequest object.
- Type
- Promise