Skip to content

Instantly share code, notes, and snippets.

@toshimaru
Created December 12, 2012 16:56
Show Gist options
  • Save toshimaru/4269484 to your computer and use it in GitHub Desktop.
Save toshimaru/4269484 to your computer and use it in GitHub Desktop.
$.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
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment