JSFiddle - React, Tailwind, and code Playground
by Himanshu Joshi
HTML
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
JavaScript
/*var deferred = $.Deferred();
deferred.done(function(value) {
alert(value);
});
deferred.resolve("hello world");
////////////////////////////////////////////////////
var post = $.ajax({
url: "/echo/json/",
data: {json: JSON.stringify({firstName: "Jose", lastName: "Romaniello"})} ,
type: "POST"
});
post.done(function(p){
alert(p.firstName + " saved.");
});
post.fail(function(){
alert("error!");
});
///////////////////////////////////////////////////
function getCustomerSSNById(customerId){
return $.post("/echo/json/", {
json: JSON.stringify({firstName: "Jose", lastName: "Romaniello", ssn: "123456789"})
}).pipe(function(p){
return p.ssn;
});
}
function getPersonAddressBySSN(ssn){
return $.post("/echo/json/", {
json: JSON.stringify({
ssn: "123456789",
address: "Siempre Viva 12345, Springfield" })
}).pipe(function(p){
return p.address;
});
}
function getPersonAddressById(id){
return getCustomerSSNById(id)
.pipe(getPersonAddressBySSN);
}
getPersonAddressById(123)
.done(function(a){
alert("The address is " + a);
});*/
/////////////////////////////////////////////////////////////////////////
function getCustomer(customerId){
var d = $.Deferred();
$.post(
"/echo/json/",
{json: JSON.stringify({firstName: "Jose", lastName: "Romaniello", ssn: "123456789"})}
).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" })
}).pipe(function(p){
return p.address;
});
}
$.when(getCustomer(123), getPersonAddressBySSN("123456789"))
.done(function(person, address){
alert("The name is " + person.firstName + " and the address is " +...