Last active
August 29, 2015 14:07
-
-
Save ethyde/df75c8f2f495a57fe0e7 to your computer and use it in GitHub Desktop.
jQuery Ajax with deffered Object (jQuery 1.9).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jqxhr = $.ajax({ | |
beforeSend: function(){ | |
console.log('Before send request'); | |
}, | |
dataType: 'json', | |
url: 'json.json' | |
}) | |
.done(function( data, textStatus, jqXHR ) { | |
var $context = $(document.getElementById('content')), | |
list = '<ul>', | |
dataLength = data.length; | |
for (var i = 0; i < dataLength; i++) { | |
list += '<li>' + data[i].about + '</li>'; | |
} | |
list += '<ul>'; | |
$context.append(list); | |
}) | |
.fail(function( jqXHR, textStatus, errorThrown ) { | |
console.log('error : ', textStatus); | |
}) | |
.always(function( a, textStatus, b ) { | |
// .allway() has same arguments like .done() or .fail() | |
// on success => a = data, b = jqXHR | |
// on error => a = jqXHR, b = errorThrown | |
console.log('first time allways textStatus : ', textStatus); | |
}); | |
jqxhr.always(function( a, textStatus, b ) { | |
console.log('second time allways textStatus : ', textStatus); | |
}); | |
jqxhr.done(function( data, textStatus, jqXHR ) { | |
console.log('second time done textStatus : ', textStatus); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment