AW2.Ajax Class
aw2 library ajax (jquery implementation)
Methods
ajax
()
Object
the core AJAX call to an endpoint offering all options
Returns:
call
-
url
-
[data]
-
[cb]
-
[error]
-
[type]
make an AJAX call to an endpoint returning a specified type
Parameters:
-
url
Stringthe URL of the endpoint
-
[data]
Object optionalan object of arguments for the ajax call
-
[cb]
Function optionalcallback function executed on success
-
[error]
Function optionalcallback function executed on error
-
[type]
String optionaltype of response
Returns:
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]
make an AJAX call to an endpoint returning HTML
Parameters:
-
url
Stringthe URL of the endpoint
-
[data]
Object optionalan object of arguments for the ajax call
-
[cb]
Function optionalcallback function executed on success
-
[error]
Function optionalcallback function executed on error
Returns:
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]
make an AJAX call to an endpoint returning JSON
Parameters:
-
url
Stringthe URL of the endpoint
-
[data]
Object optionalan object of arguments for the ajax call
-
[cb]
Function optionalcallback function executed on success
-
[error]
Function optionalcallback function executed on error
Returns:
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]
make an AJAX call to an endpoint returning JSONP
Parameters:
-
url
Stringthe URL of the endpoint
-
[data]
Object optionalan object of arguments for the ajax call
-
[cb]
Function optionalcallback function executed on success
-
[error]
Function optionalcallback function executed on error
Returns:
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]
external handler for asynchronous AJAX calls allowing callbacks to be specified at some point after the initial call
Parameters:
-
[args]
Object optional multipleone or more ajax request objects
Returns:
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');
});