API Docs for: 1.0.2
Show:

AW2.Ajax Class

Module: aw2

aw2 library ajax (jquery implementation)

Item Index

Methods

ajax

() Object

the core AJAX call to an endpoint offering all options

Returns:

Object: ajax request object

call

(
  • url
  • [data]
  • [cb]
  • [error]
  • [type]
)
Object

make an AJAX call to an endpoint returning a specified type

Parameters:

  • url String

    the URL of the endpoint

  • [data] Object optional

    an object of arguments for the ajax call

  • [cb] Function optional

    callback function executed on success

  • [error] Function optional

    callback function executed on error

  • [type] String optional

    type of response

Returns:

Object: ajax request object

Example:

Sample with callback

    $aw2.call("myRequest.cfm", {a: 1}, function(data) {
        alert("do something with " + data);
    }, "json");

Sample with success and error callback

    $aw2.call("myRequest.cfm", {a: 1}, function(data) {
        alert("do something with " + data);
    }, function() {
        alert('Error');
    }, "json");

callHTML

(
  • url
  • [data]
  • [cb]
  • [error]
)
Object

make an AJAX call to an endpoint returning HTML

Parameters:

  • url String

    the URL of the endpoint

  • [data] Object optional

    an object of arguments for the ajax call

  • [cb] Function optional

    callback function executed on success

  • [error] Function optional

    callback function executed on error

Returns:

Object: ajax request object

Example:

Sample with callback

    $aw2.callHTML("myRequest.cfm", {a: 1}, function(data) {
        alert("do something with " + data);
    });

Sample with success and error callback

    $aw2.callHTML("myRequest.cfm", {a: 1}, function(data) {
        alert("do something with " + data);
    }, function() {
        alert('Error');
    });

callJSON

(
  • url
  • [data]
  • [cb]
  • [error]
)
Object

make an AJAX call to an endpoint returning JSON

Parameters:

  • url String

    the URL of the endpoint

  • [data] Object optional

    an object of arguments for the ajax call

  • [cb] Function optional

    callback function executed on success

  • [error] Function optional

    callback function executed on error

Returns:

Object: ajax request object

Example:

Sample with success callback

    $aw2.callJSON("http://openbd.org/manual/api/?/function/fileread/", '', function(data) {
        alert("do something with " + data);
    });

Sample with success and error callback

    $aw2.callJSON("http://openbd.org/manual/api/?/function/fileread/", '', function(data) {
        alert("do something with " + data);
    }, function() {
        alert('Error');
    });

callJSONP

(
  • url
  • [data]
  • [cb]
  • [error]
)
Object

make an AJAX call to an endpoint returning JSONP

Parameters:

  • url String

    the URL of the endpoint

  • [data] Object optional

    an object of arguments for the ajax call

  • [cb] Function optional

    callback function executed on success

  • [error] Function optional

    callback function executed on error

Returns:

Object: ajax request object

Example:

Sample with callback

    $aw2.callJSONP("myRequest.cfm", {a: 1}, function(data) {
        alert("do something with " + data);
    });

Sample with success and error callback

    $aw2.callJSONP("myRequest.cfm", {a: 1}, function(data) {
        alert("do something with " + data);
    }, function() {
        alert('Error');
    });

when

(
  • [args]
)
Object

external handler for asynchronous AJAX calls allowing callbacks to be specified at some point after the initial call

Parameters:

  • [args] Object optional multiple

    one or more ajax request objects

Returns:

Object: returns an object with methods to specify various callbacks for what to do when the passed ajax objects return

Example:

Sample using when and done

    var ajaxRequest = $aw2.callJSON("myRequest.cfm");
    $aw2.when(ajaxRequest).done(function(response) {
        alert("Do something with " + response);
    });

Sample using when, done and fail. .fail() is a callback to execute on failed ajax

    var ajaxRequest = $aw2.callJSON("myRequest.cfm");
    $aw2.when(ajaxRequest).done(function(response) {
        alert("Do something with " + response);
    }).fail(function() {
        alert('Failed');
});