Namespace LABKEY.Ajax
Utility for making XHR.
Defined in: Ajax.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
<static> |
LABKEY.Ajax.request(config)
Make a XMLHttpRequest nominally to a LabKey instance.
|
Method Detail
<static>
{XMLHttpRequest}
LABKEY.Ajax.request(config)
Make a XMLHttpRequest nominally to a LabKey instance. Includes success/failure callback mechanism,
HTTP header configuration, support for FormData, and parameter encoding amongst other features.
- Parameters:
- config
- An object which contains the following configuration properties.
- {String} config.url
- the url used for the XMLHttpRequest. If you are making a request to the LabKey Server instance see LABKEY.ActionURL.buildURL for helpful URL construction.
- {String} config.method Optional
- the HTTP request method used for the XMLHttpRequest. Examples are "GET", "PUSH, "DELETE", etc. Defaults to "GET" unless jsonData is supplied then the default is changed to "POST". For more information, see this HTTP request method documentation.
- {Object} config.jsonData Optional
- data provided to the XMLHttpRequest.send(data) function. If the request is method "POST" this is the body of the request.
- {Object} config.params Optional
- An object representing URL parameters that will be added to the URL. Note, that if the request is method "POST" and jsonData is not provided these params will be sent via the body of the request.
- {Object} config.headers Optional
- Object specifying additional HTTP headers to add the request.
- {Mixed} config.form Optional
- FormData or Object consumable by FormData that can be used to POST key/value pairs of form information. For more information, see FormData documentation.
- {Function} config.success Optional
- A function called when a successful response is received (determined by XHR readyState and status).
It will be passed the following arguments:
- xhr: The XMLHttpRequest where the text of the response can be found on xhr.responseText amongst other properties
- originalConfig: The config originally supplied to LABKEY.Ajax.request
- {Function} config.failure Optional
- A function called when a failure response is received (determined by
XHR readyState, status, or ontimeout if supplied). It will be passed the following arguments:
- xhr: The XMLHttpRequest where the text of the response can be found on xhr.responseText amongst other properties
- originalConfig: The config originally supplied to LABKEY.Ajax.request
- {Function} config.callback Optional
- A function called after any success/failure response is received. It will
be passed the following arguments:
- originalConfig: The config originally supplied to LABKEY.Ajax.request
- success: boolean value that is true if the request was successful
- xhr: The XMLHttpRequest where the text of the response can be found on xhr.responseText amongst other properties
- {Mixed} config.scope Optional
- A scope for the callback functions. Defaults to "this".
- {Mixed} config.timeout Optional
- If a non-null value is supplied then XMLHttpRequest.ontimeout will be hooked to failure.
- Returns:
- {XMLHttpRequest}