I am trying to send a form data, converted to JSON, to another page with jQuery, . However, I believe my POST method is not working as I am always getting the error message- which only says "error". Can anyone help me catch the exact error or tinker the code for making it correct?
I have checked that the data is properly getting JSONed (the first alert is showing the correct form data).
$('#submit').click(function () {
var rows = [];
$('#Tinfo tbody tr').each(function () {
var tds = $(this).children('td'); /* taking all the td elements of the current tr */
rows.push({
'sl': tds.eq(0).find('input').val(),
'tname': tds.eq(1).find('input').val(),
'ttype': tds.eq(2).find('select').val(),
'tduration': tds.eq(3).find('input').val()
});
});
rows = JSON.stringify(rows);
alert(rows);
/* Using the post function to send data over to the database handler page */
$.ajax({
type: "POST",
url: "/Insert",
data: rows,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status) {
alert(status);
},
error: function (xhr, textStatus, error) {
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
});