This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script src="http://malsup.github.com/jquery.blockUI.js"></script> | |
<link rel="stylesheet" href="style.css" /> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<div>Live demo : <a href='http://jsfiddle.net/jfromaniello/AjwaV/40/light/' target='_blank'>http://jsfiddle.net/jfromaniello/AjwaV/40/light/</a></div> | |
<ul> | |
<li>First name: <span id="firstName"></span></li> | |
<li>Address: <span id="address"></span></li> | |
</ul> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCustomer(customerId){ | |
var d = $.Deferred(); | |
$.post( | |
"/echo/json/", | |
{json: JSON.stringify({firstName: "Jose", lastName: "Romaniello", ssn: "123456789"}), | |
delay: 4} | |
).done(function(p){ | |
d.resolve(p); | |
}).fail(d.reject); | |
return d.promise(); | |
} | |
function getPersonAddressBySSN(ssn){ | |
return $.post("/echo/json/", { | |
json: JSON.stringify({ | |
ssn: "123456789", | |
address: "Siempre Viva 12345, Springfield" }), | |
delay: 2 | |
}).pipe(function(p){ | |
return p.address; | |
}); | |
} | |
function load(){ | |
$.blockUI({message: "Loading..."}); | |
var loadingCustomer = getCustomer(123) | |
.done(function(c){ | |
$("span#firstName").html(c.firstName) | |
}); | |
var loadingAddress = getPersonAddressBySSN("123456789") | |
.done(function(address){ | |
$("span#address").html(address) | |
}); | |
$.when(loadingCustomer, loadingAddress) | |
.done($.unblockUI); | |
} | |
load(); |
No comments:
Post a Comment