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: - dynamicBase (String) – See
dynamicBase. - staticBase (String) – See
staticBase. - defaultQuery (String|Function) – Defaults to
"". SeedefaultQuery.
-
read-only
dynamicBase¶ Type: String The dynamic base for ajax calls.
-
read-only
defaultQuery¶ 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: - err (Error|null) – A possible error.
- content (String) – The content of the retrieved file.
- url (String) – The URL to a file to retrieve, relative to
-
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: - err (Error|null) – A possible error.
- data – The value of the data attribute of the response.
- res (Object) – The response object.
- dynamicBase (String) – See