mixins/ajax

mixin AjaxMixin(dynamicBase, staticBase[, defaultQuery])

Mixin that provides ajax functionality, such as GET and POST methods as well as cached file retrieval.

Arguments:
read-onlydynamicBase
Type:String

The dynamic base for ajax calls.

read-onlystaticBase
Type:String

The static base for file retrievals via getFile().

read-onlydefaultQuery
Type:String|Function

The default query string when sending ajax requests.

Note

When this value is assigned to a function, the getter still returns a string by evaluating the function without arguments.

staticURL(url)

Returns the fully prefixed URL for a static resource. If the given url starts with a slash it will resturn a global URL (same as calling this function on the vispa object).

Arguments:
  • url (String) – The URL of the resource to get.
Returns:

The fully prefixed URL.

Return type:

String

dynamicURL(url)

Returns the fully prefixed URL for a dynamic resource (usually ajax). If the given url starts with a slash it will resturn a global URL (same as calling this function on the vispa object).

Arguments:
  • url (String) – The URL of the resource to get.
Returns:

The fully prefixed URL.

Return type:

String

getFile(url[, callback])

Retrieves the content of a file. This function caches file contents identified by url.

Arguments:
  • url (String) – The URL to a file to retrieve, relative to staticBase.
Callback args:
  1. err (Error|null) – A possible error.
  2. content (String) – The content of the retrieved file.
ajax(method, url[, data][, callback])

Ajax wrapper method that represents the core of any ajax call. It should be used instead of jQuery’s methods since vispa implements the callback-as-last-argument style instead of using jqXHR/Deferred objects.

Arguments:
  • method (String) – The http method to use. Currently, only “GET”, “POST” and “DELETE” are supported.
  • url (String) – The url of the endpoint to use, relative to the dynamic base.
  • data (Object|String) – The data to send. When a string is passed, it is assumed that it is an encoded json object and the content type will be set accordingly. When an object is passed, it is forwarded to jQuery’s ajax method the normal way.
Callback args:
  1. err (Error|null) – A possible error.
  2. data – The value of the data attribute of the response.
  3. res (Object) – The response object.
GET(...)

Convenience wrapper around ajax() for sending GET requests.

POST(...)

Convenience wrapper around ajax() for sending POST requests.

DELETE(...)

Convenience wrapper around ajax() for sending DELETE requests.