javascript - Knockout.js posting a form -
what simplest method of posting form server when clicking submit button using knockout.js?
this have not posting. broken saveform function?
// here's data model save option var self = this; var viewmodel; $.getjson('@url.content("~/api/mydata")', function (data) { viewmodel = ko.mapping.fromjs(data); self.save = function (form) { alert("could transmit server"); }; viewmodel.saveform = function () { var jsondata = ko.mapping.tojson(viewmodel); $.ajax({ type: "post", url: '@url.content("~/api/mydata")', data: jsondata }); }; ko.applybindings(viewmodel); }); <button type="submit">save</button>
probably worth putting line
debugger;
before
viewmodel = ko.mapping.fromjs(data);
and checking happens viewmodel in firebug. "viewmodel = ko.mapping.fromjs(data);" replace in viewmodel json loading. includeds function saveform
Comments
Post a Comment