mixins/ajax =========== .. js:mixin:: AjaxMixin(dynamicBase, staticBase[, defaultQuery]) Mixin that provides ajax functionality, such as GET and POST methods as well as cached file retrieval. :param String dynamicBase: See :js:attr:`dynamicBase`. :param String staticBase: See :js:attr:`staticBase`. :param String|Function defaultQuery: Defaults to ``""``. See :js:attr:`defaultQuery`. .. js:attribute:: dynamicBase read-only :type: String The dynamic base for ajax calls. .. js:attribute:: staticBase read-only :type: String The static base for file retrievals via :js:func:`getFile`. .. js:attribute:: defaultQuery read-only :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. .. js:function:: 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). :param String url: The URL of the resource to get. :return: The fully prefixed URL. :rtype: String .. js:function:: 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). :param String url: The URL of the resource to get. :return: The fully prefixed URL. :rtype: String .. js:function:: getFile(url[, callback]) Retrieves the content of a file. This function caches file contents identified by *url*. :param String url: The URL to a file to retrieve, relative to :js:attr:`staticBase`. :callback Error|null err: A possible error. :callback String content: The content of the retrieved file. .. js:function:: 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. :param String method: The http method to use. Currently, only "GET", "POST" and "DELETE" are supported. :param String url: The url of the endpoint to use, relative to the dynamic base. :param Object|String data: 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 Error|null err: A possible error. :callback data: The value of the *data* attribute of the response. :callback Object res: The response object. .. js:function:: GET(...) Convenience wrapper around :js:func:`ajax` for sending GET requests. .. js:function:: POST(...) Convenience wrapper around :js:func:`ajax` for sending POST requests. .. js:function:: DELETE(...) Convenience wrapper around :js:func:`ajax` for sending DELETE requests.