jQuery Deferred
Callbacks in Queue
by revathskumar
HTML
<script src="http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js"></script>
JavaScript
var data = {
json: $.toJSON({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
}),
delay: 3
}
function doAjax(debug) {
var debug = true;
var req = $.ajax({
url : '/echo/json/',
data: data,
dataType : 'json',
success : function(resp) {
console.log(resp);
}
});
if (debug) {
req.success(function(resp) {
console.log("let's see that again!", resp);
});
}
// return the request object so other
// things can bind to it too!
return req;
}
doAjax().success(function(resp){
console.log("Once more, with feeling!", resp);
});