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
async
value for the Ajax calls.- Since:
-
- 1.0.0
-
<static, constant> DEFAULT_SCOPE
-
Provides the default
scope
value for callbacks.- Since:
-
- 1.0.0
-
<static, constant> DEFAULT_TIMEOUT
-
Provides the default
timeout
(in milliseconds) for the Ajax calls.- Since:
-
- 1.0.0
-
<static, constant> DEFAULT_WITH_CREDENTIALS
-
Provides the default
withCredentials
value for 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}`); });
Parameters:
Name Type Description method
String The HTTP method to use for the request. Note that the method name is case-sensitive and should be all caps.
url
String The URL to which to send the request.
options
Object An object which may contain the following properties:
Properties
Name Type Argument Default Description async
Boolean <optional>
true true
if this request should run asynchronously.false
if 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).headers
Object <optional>
Request headers to set for the request.
scope
Object <optional>
window The scope in which to execute the callbacks (refers to the "this" parameter for the callback functions).
jsonData
Object | String <optional>
JSON data to use as the post.
withCredentials
Boolean <optional>
false The value for the withCredentials property of the XMLHttpRequest object.
beforeRequest
function <optional>
The function to be called before a network request is made to retrieve a data object.
afterRequest
function <optional>
The function to be called upon receipt of the HTTP response. This function is called regardless of success or failure. The callback is passed the following parameters:
Properties
Name Type Description response
XMLHttpRequest The XMLHttpRequest object containing the response data. See XMLHttpRequest for details about accessing elements of the response.
- Since:
-
- 1.0.0
Throws:
-
If invalid arguments.
- Type
- TypeError
Returns:
A Promise that resolves to an XMLHttpRequest object.
- Type
- Promise