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_SCOPE
-
Provides the default
scopevalue 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
withCredentialsvalue 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.
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. To process returned data, use a success (or afterRequest) callback in the request options object.
Example Usage:
mindsmine.Ajax.request( "GET", "valid URL", { headers: { "Accept" : "some value", "Content-Type" : "some value", "Authorization" : "some value" }, success: function (request) { var responseJSON = JSON.parse(request.responseText); console.log(responseJSON); }, failure: function (request) { console.log("HTTP error " + request.status); } } );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.
scopeObject <optional>
window The scope in which to execute the callbacks (refers to the "this" parameter for the callback functions).
jsonDataObject | String <optional>
JSON data to use as the post.
withCredentialsBoolean <optional>
false trueto add thewithCredentialsproperty to the XHR object.beforeRequestfunction <optional>
The function to be called before a network request is made to retrieve a data object.
afterRequestfunction <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 responseXMLHttpRequest The XMLHttpRequest object containing the response data. See XMLHttpRequest for details about accessing elements of the response.
successfunction The function to be called upon success of the request. The callback is passed the following parameters:
Properties
Name Type Description responseXMLHttpRequest The XMLHttpRequest object containing the response data. See XMLHttpRequest for details about accessing elements of the response.
failurefunction The function to be called upon failure of the request. The callback is passed the following parameters:
Properties
Name Type Description responseXMLHttpRequest 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