A small post to present the complete JQuery.ajax syntax (http://api.jquery.com/jQuery.ajax/). I’ve also added a simple timer.
You can start from this example to observe the diferent status 😉
{codecitation class= »brush: javascript; »}
function log(msg) {
if (window.console) // IE8+ compliant 😉
console.log(msg);
}
function callServer(url, data, callbackSuccess, callbackError) {
log(« begin » + url);
try {
var t = new Date().getTime();
var object = $.ajax(url, {
complete : function(query, status) {
log(« complete »);
},
// contentType : »application/json »,
// dataType: »jsonp »,
// jsonp:’onJSONPLoad’,
data : {
« data » : data
},
error : function(d, s, q) {
callbackError(d, s, q, t);
},
success : function(d, s, q) {
callbackSuccess(d, s, q, t);
},
error : function(query, status, error) {
log(« error » + status);
},
success : function(data, status, query) {
log(« success » + status);
},
type : ‘POST’,
});
object.done(function(data, textStatus, jqXHR) {
log(« done » + textStatus);
});
object.fail(function(query, textStatus, error) {
log(« fail » + textStatus);
});
object.always(function(query, textStatus, error) {
log(« always » + textStatus);
});
log(« ajax fired »);
} catch (e) {
log(« exception » + e);
}
log(« end » + url);
}
{/codecitation}
Â