I want to send post request with data from html form which will be filled by user. I would like to use jquery to achieve this. Here is my attempt (not working):
$(function () {
$("#create").click(function (event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "/home/new",
data: $(this).serialize(),
success: function (data, textStatus, jqXhr) {
//call "home/new" with data from html form as json and update current view with returned data
console.log("success");
},
error: function () {
alert("error");
}
});
});
});
<html lang="en">
<head>
<script type="text/javascript" src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/Helpers.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Title Goes Here</title>
</head>
<body>
<form>
Note:<br>
</form>
<textarea rows="4" cols="50" name="note" form="form">
</textarea>
<br/>
<input type="date" name="day" form="form">
<input type="submit" id="create" value="Submit" form="form">
</body>
</html>