Created
May 31, 2012 21:52
-
-
Save ericktai/2846570 to your computer and use it in GitHub Desktop.
Chained Calls
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
/* | |
For chained functions, simply call the second, third, fourth functions in the "success" callbacks | |
Callbacks: http://www.stackmob.com/devcenter/docs/Javascript-SDK-API#a-success | |
These calls will execute in order 1 by 1, not simultaneously. | |
*/ | |
var user = new StackMob.User({ username: 'chucknorris', password: 'myfists' }); | |
user.login(false, { | |
success: function(model) { | |
//by the way, the full user object is returned in the current API in "model" | |
//but if you wanted to do a second call.. | |
user.fetch({ | |
success: function(model) { | |
//and a third call | |
user.fetch({ | |
success: function(model) { | |
//and a fourth call | |
var todos = new Todos(); | |
todos.fetch(); | |
} | |
}) | |
} | |
}); | |
}, | |
error: function() { | |
//some error | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment