Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$.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

This comment has been minimized.

Copy link
Owner Author

toshimaru commented Jan 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.