javascript - JSON 不发布到 PHP
问题描述
我正在将值从动态表中提取到 JSON,但不知何故我无法将 JSON 数据发布到 PHP。哪里出错了?我将非常感谢一些帮助,我最终想插入到 MSQL db
test.php 上的错误 => 注意:未定义的索引:p_row
<script type="text/javascript">
var table = document.getElementById('table'),
rows = table.getElementsByTagName('tr'),
i, j, cells, OS_d, roleApp_d, Men_d, vcpu_d, Val_d, Per_d, hw_d;
var p_row = '[';
for (i = 1, j = rows.length; i < j; ++i) {
cells = rows[i].getElementsByTagName('td');
if (!cells.length) {
continue;
}
p_row += "{";
p_row += '"' + cells[1].firstChild.value + '",';
p_row += '"' + cells[2].firstChild.value + '",';
p_row += '"' + cells[3].firstChild.value + '",';
p_row += '"' + cells[4].firstChild.value + '",';
p_row += '"' + cells[5].firstChild.value + '",';
p_row += '"' + cells[6].firstChild.value + '",';
p_row += '},';
}
p_row = (p_row).replace(new RegExp("[,]+$"), "");
p_row += ']';
$.ajax({
url: 'http://localhost/portal/test.php',
type: 'POST',
content: 'application/json',
dataType: 'json',
data: JSON.stringify(p_row),
success: function (data, status, xhr) {
}
});
</script>
测试.php
<?php
$data = json_decode($_POST["p_row"]);
echo $_POST["p_row"];
?>
解决方案
推荐阅读
- c# - 使用动态和静态键的混合反序列化 JSON
- fortran - 如何使用OO Fortran获得五个数字中最小的数字
- arrays - JSON-LD 缺少“}”或对象成员名称。语法错误:需要值、对象或数组。如何解决这个问题
- flutter - Aqueduct 不响应 Flutter 获取请求
- javascript - 无法使用 Django 加载静态文件
- python-3.x - 如何在python的子类中创建附加属性?
- node.js - 如何在 React + Webpack 中安装和配置外部模块
- testing - 当我们获得新的 Web 应用程序时,如何确定需要哪种类型的测试(手动或自动化)?
- c# - DataGridViewColumnSortMode 设置为 NotSortable,但某些列仍会排序
- templates - 如何解析具有格式化字符串变量的模板?