I am new to using Knockout.js and for that matter JavaScript as well. I went through their tutorials and tried to modify the example to load data from server as below. Can anyone please point what's wrong with my code
JavaScript:
jQuery(document).ready(function () {
MyViewModel = function()
{
var self =this;
self.name = ko.observable("");
self.getJson = function()
{
jQuery.ajax({
//Do all the work
success: function(data)
{
self.name = data.name;
}
});
}
}
myViewModelObj = new MyViewModel();
ko.applyBindings(myViewModelObj);
myViewModelObj.getJson();
});
View:
<h1 data-bind="text: name "></h1>