使用Ajax发送发帖请求并使用php

时间:2019-07-26 11:32:28

标签: php html ajax post request

我的 Ajax 需要一些帮助。

我有一个表,每一行都有一个数据属性,其中包含所有 内容

我需要它来编辑数据库条目。

我已经创建了a.php文件,该文件应该可以捕获$_POST,但是没有。

HTML:

echo "<table class='flex-container tableDH'>";
echo "<th class='flex-content thDH'>ID</th><th class='thDH'>Type</th><th class='thDH'>Serial</th><th class='thDH'>Position</th><th class='thDH'>Memo</th><th class='thDH'>Bearbeiten</th>";
foreach($o170->getAllDrives() as $dataset) {
  $json = json_encode($dataset);
  echo "<tr class='trDH' data-attribute='$json' id='".$dataset['id']."'>";
  echo "<td class='flex-item tdDH'>".$dataset['id']."</td>";
  echo "<td class='flex-item tdDH'>".$dataset['type']."</td>";
  echo "<td class='flex-item tdDH'>".$dataset['serial']."</td>";
  echo "<td class='flex-item tdDH'>".$dataset['position']."</td>";
  echo "<td class='flex-item tdDH'>".$dataset['memo']."</td>";
  echo "<td class='flex-item tdDH' style='text-align:center;'><button type='button' name='edit' onclick='editRow(".$dataset['id'].")'>Edit</button>";
  echo "<tr>";
}
echo "</table>";

AJAX:

function editRow(id) 
{
    var jsonObj = $('#'+id).data('attribute');
    console.log("Starting Ajax");
    $.ajax({
        url: './170_festplatten_edit_view.php',
        type: 'POST',
        data: {json : jsonObj},
        success: function (data) {
            console.log("ready")
            });
            console.log(data);
        }
    });
}

PHP文件:

echo "<pre>";
if(isset($_POST['json']))
{
  print_r($_POST);
  die;
}

我已经搜索了问题的各个方面,但是我似乎找不到解决方法。

0 个答案:

没有答案