Create a gist now

Instantly share code, notes, and snippets.

$.ajax({
url: "ajax.html",
success: function(data) {
alert('success!!');
},
error: function(data) {
alert('error!!!');
}
});
$.ajax({
url: "ajax.html",
}).success(function(data){
alert('success!!');
}).error(function(data){
alert('error!!!');
});
$.ajax({
url: "ajax.html",
}).done(function(data){
alert('success!!');
}).fail(function(data){
alert('error!!!');
});
$.ajax({
url: "ajax.html",
}).then(
function(data){ alert('success!!'); },
function(data){ alert('error!!'); });
var Twitter = {
search: function(query) {
var defer = $.Deferred();
$.ajax({
url: "http://search.twitter.com/search.json",
data: {
q: query,
rpp: 50
},
dataType: 'jsonp',
success: defer.resolve,
error: defer.reject
});
return defer.promise();
}
};
$('#button').on('click', function() {
Twitter.search('jquery deferred').done(function(data) {
console.log(data);
$(data.results).each(function(k,v){
$('#tweets').append(v.text + '<br/>');
});
});
});
var Twitter = {
search: function(query) {
var defer = $.Deferred();
$.ajax({
url: "http://search.twitter.com/search.json",
data: {
q: query,
rpp: 50
},
dataType: 'jsonp',
success: defer.resolve,
error: defer.reject
});
return defer.promise();
}
};
$('#button').on('click', function() {
$.when(Twitter.search('jquery deferred'), Twitter.search('jquery when'))
.then(function(data1, data2){
console.log(data1);
console.log(data2);
});
});
@toshimaru
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment