Created
August 15, 2011 23:19
-
-
Save chardcastle/1148127 to your computer and use it in GitHub Desktop.
Deferred objects with jQuery
This file contains hidden or 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
$.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