首页 > 解决方案 > 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"];
?>

标签: javascriptphpjqueryjsonajax

解决方案


推荐阅读