jQuery promise and AJAX

Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events.

HTML

<div id="output"></div>

JavaScript

// Info: http://net.tutsplus.com/tutorials/javascript-ajax/wrangle-async-tasks-with-jquery-promises/

function getPromise(){

  var promise  = $.Deferred();
  return promise;
}
$(document).ready(function(){
getPromise().then(function(res){
	console.log("===",res);
})
})


/* function logger(txt) {
    $('#output').append(txt + "<br>");
}

var url = '/echo/json';
var data = {'test': 'hello'};
var promise = $.getJSON(url, data, function(json) {
    //alert(JSON.stringify(json));
    logger('ajax1 done');
});

promise.done(function(data) {
    logger('ajax1 ok: ' + JSON.stringify(data));
});

var url = 'http://cross-domain.com';
promise = $.getJSON(url, data, function(json) {
    logger('ajax done');
});

promise.fail(function(data) {
    logger('ajax2 fail: ' + JSON.stringify(data));
});


logger('script done'); */