Extensions & Helpers
ajax
The ajax extension provides The following additional functionality on top
of the base jQuery Ajax function.
- Automatically adds the Authorization header using globally configured bearerToken.
-
When not specified the
contentTypeis added and assumed to beapplication/json. -
Adds an
abortedfunction that is only called when the client aborts the request. -
Adds a
failedfunction that is only called when the request fails not when the request is aborted.
By default jQuery.ajax calls the fail handler for both client aborted requests as well as
server failed requests. For UX purposes a developer may want to handle these situations differently,
for example when a client aborts the request ,an error banner is likely not needed. Atlas assumes
the absence of XHR headers implies a client aborted request and will call the
aborted handler.
atlas.ajax({
url: "..."
}).aborted(function(xhr, textStatus, textReason){
// client cancled the request
}).failed(function(xhr, textStatus, textReason){
// an error was returned from the server
});
Parameters
| Name | Type | Description |
|---|---|---|
| noBearerToken | Boolean | When true the bearer token will not be added. Use this if you want to make calls to APIs that do not need the bearer token or should not get the bearer Token. |
| Includes all options in the jQuery AJAX Documentation | ||