JSONに変換されたフォームデータをjQueryで別のページに送信しようとしています。ただし、「エラー」としか表示されないエラーメッセージが常に表示されるため、POST メソッドが機能していないと思います。正確なエラーをキャッチしたり、コードを修正して正しくするのを手伝ってくれる人はいますか?
データが適切に JSON 化されていることを確認しました (最初のアラートは正しいフォーム データを示しています)。
$('#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);
}
});
});