Created
November 9, 2013 11:35
-
-
Save Chitrank-Dixit/7384546 to your computer and use it in GitHub Desktop.
Send the Form Data as JSON in Knockoutjs
This file contains 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
// write this under Knockout viewModel | |
// This is an example to send all the users comments to the server | |
// Basic Example we can fit it for other purposes as well | |
self.save = function() { | |
return $.ajax({ | |
url: "comments.php", | |
contentType: 'application/json', | |
type: 'POST', | |
data: JSON.stringify({ | |
'comment': self.comment(), | |
'name' : "Chitrank", | |
'uid' : "23", | |
}), | |
success: function(data) { | |
console.log("Pushing to comment array"); | |
self.comments.push(new Comment({ comment: data.comment, name: data.name, uid: data.uid })); | |
return; | |
}, | |
error: function() { | |
return console.log("Failed"); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment