Skip to content

Instantly share code, notes, and snippets.

@chardcastle
Created August 15, 2011 23:19
Show Gist options
  • Save chardcastle/1148127 to your computer and use it in GitHub Desktop.
Save chardcastle/1148127 to your computer and use it in GitHub Desktop.
Deferred objects with jQuery
$.post(ENV.app_url+"/tab/answer", data, function(json){
// create a deferred object
var dfd = $.Deferred();
var action = {
add_response: function(json){
console.log('added message');
$("#question_response")
.html(json.message)
},
refresh_cufon: function(){
console.log('refreshed cufon');
Cufon.refresh();
},
refresh_question: function(){
// Increase compatibility with unnamed functions
window.setTimeout(function() {
console.log('running next');
$("#questions")
.find("#question_"+(parseInt(position)))
.hide("slow")
.end()
.find("#question_response")
.empty()
.end()
.find("#question_"+(parseInt(position) + 1))
.show("fast")
.end();
}, 2000);
}
}
dfd.done(action.add_response, action.refresh_cufon, action.refresh_question).resolve(json);
},'json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment