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 contentType is added and assumed to be application/json.
  • Adds an aborted function that is only called when the client aborts the request.
  • Adds a failed function 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.

The bearerToken will only be inserted for secure (https) calls to the CenturyLink Cloud APIs. Currently three environments are supported: api.qa.ctl.io, api.dev.ctl.io, and api.ctl.io. This is to prevent leaking of a users bearerToken to non CenutryLink Cloud assets.

    
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
Includes all options in the jQuery AJAX Documentation