I am pulling values form a dynamic table to JSON but somehow I am Unable to POST JSON data to PHP. Where am going wrong? I would greatly appreciate some assistance, I would eventually like to INSERT to MSQL db
Error on test.php => Notice: Undefined index: 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>
test.php
<?php
$data = json_decode($_POST["p_row"]);
echo $_POST["p_row"];
?>