Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Last active December 19, 2015 10:49
Show Gist options
  • Select an option

  • Save danielmackay/5943433 to your computer and use it in GitHub Desktop.

Select an option

Save danielmackay/5943433 to your computer and use it in GitHub Desktop.
Posting JSON with Knockout.
<form action="/tasks/saveform" method="post">
<hidden name="tasks" data-bind="value: ko.toJSON(tasks)"></hidden >
<button type="submit">Save</button>
</form>
self.save = function() {
$.ajax("/tasks", {
data: ko.toJSON({ tasks: self.tasks }),
type: "post", contentType: "application/json",
success: function(result) { alert(result) }
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment