syuichi-tsuji
6/10/2014 - 1:35 PM

jquery1.4.js

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);
   });
});
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/>'); 
       });
   });
});
$.ajax({
    url: "ajax.html",
}).then(
function(data){ alert('success!!'); },
function(data){ alert('error!!');   });
$.ajax({
    url: "ajax.html",
}).done(function(data){
    alert('success!!');
}).fail(function(data){
    alert('error!!!');
});
$.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!!!');
    }
});