使用Php、Ajax和JSON在数据库中保存动态记录
我有一个表,每行包含1 DB记录的字段使用Php、Ajax和JSON在数据库中保存动态记录,php,mysql,ajax,json,Php,Mysql,Ajax,Json,我有一个表,每行包含1 DB记录的字段 表行是动态添加和删除的 我想使用ajax将所有文本框数据发送到php文件 下表所示 <table id="tblDmc" frame="box" rules="all" width="100%"> <tr> <th>Subject</th><th>Total Marks</th><th>Obtained</th&
表行是动态添加和删除的
我想使用ajax将所有文本框数据发送到php文件
下表所示
<table id="tblDmc" frame="box" rules="all" width="100%">
<tr>
<th>Subject</th><th>Total Marks</th><th>Obtained</th><th>Class Highest</th><th>Remarks</th><th> </th>
</tr>
<tr class="subRecord">
<td><input type="text" class="dmcTxt subject"></td>
<td><input type="number" class="dmcTxt total"></td>
<td><input type="number" class="dmcTxt obtained"></td>
<td><input type="number" class="dmcTxt highest"></td>
<td><input type="text" class="dmcTxt remarks"></td>
<td><a href="#" class="removeRow">x<a></td>
</tr>
</table>
stringify(data1)返回以下内容
[
{"std_id":"6","month":"4","percent":"77","grade":"1","position":"33","curricular":"abc"},
{"subject":"Maths","total":"100","obtained":"99","highest":"100","remarks":"remarks"},
{"subject":"Physics","total":"100","obtained":"94","highest":"99","remarks":"emarks"}
]
savedmc.php中的代码是
<?php print_r($_POST); ?>
返回空数组()的
我的问题是如何通过ajax将上述json对象/数组发送到php文件,或者任何替代方案?用以下版本替换JS代码中的ajax调用:
$.ajax({
url:'savedmc.php',
type:'POST',
dataType: "json",
data: JSON.stringify(data1),
contentType: "application/json; charset=UTF-8",
success: function(e){
alert(e);
}
});
仍然没有收到,它返回空数组您可以使用firebug或chrome控制台检查您使用ajax发送的参数吗?undefined=&undefined=json有效,我还应该测试什么,以及网络选项卡上显示了什么(chrome上按f12)?方法:post,状态:200/ok,键入:text/html,以及时间、大小,当您单击“网络”选项卡中的页面链接时,initiatorIt'不显示json数据?是的,它在“表单数据”选项卡中显示数据,我是否需要其他内容来访问该数据?您可以在“网络”选项卡上发布数据的屏幕截图吗?
$.ajax({
url:'savedmc.php',
type:'POST',
dataType: "json",
data: JSON.stringify(data1),
contentType: "application/json; charset=UTF-8",
success: function(e){
alert(e);
}
});