Skip to content

Instantly share code, notes, and snippets.

@kenstone
Created September 5, 2012 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenstone/3629483 to your computer and use it in GitHub Desktop.
Save kenstone/3629483 to your computer and use it in GitHub Desktop.
Knockout View Model Method Call without deferreds
var viewModel = function() {
var self = this;
self.description = ko.observable('hello');
self.get = function(words) {
$.ajax({
url: "/echo/json",
dataType: "json",
type: "POST",
data: {
"text": words
},
success: function(data) {
self.description(words);
},
error: function(data) {
}
});
};
};
$(function() {
var instance = new viewModel();
ko.applyBindings(instance);
instance.get('something');
});​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment