通过 javascript 传递 PHP 变量并再次返回

Passing PHP variable through javascript and back again

我有一个生成很多行的表单。每行都有一个 "Add Notes" 按钮,像这样

<button onclick=\"myFunction()\">Add Note</button>

并通过此代码段触发弹出输入

<script language="JavaScript" type="text/javascript">
    function myFunction() {
        var x;
        var note = prompt("Customer Note","Write your customer note here...");

        if (note != null) {
            document.getElementById("notes").value = note;
            document.getElementById("notesForm").submit();
        } 
    else{
       return false;
        }
    }
</script>

并通过此部分提交表单

<form action=\"http://calls.fantomworks.com/functions/notes.php\" 
id='notesForm' name='notesForm' method='post'>
    <input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
    <input type='hidden' id='notes' name='notes' />
    </form>

问题是注释被传递到第一行而不是正确的 {$row['ID']}。我如何通过这个弹出窗口传递 {$row['ID']} 并返回到表单,以便它正确地进入下面的注释处理器??

$notesID = $_POST['ID'];
$note = $_POST['notes'];
$note = mysql_real_escape_string($note);
$date= date('Y-m-d');

$result = mysql_query("UPDATE Project_Submissions SET 
                       Notes=CONCAT(Notes,'<br />".$date." ".$note."') 
                       WHERE ID ='".$notesID."'");

我很迷茫,真的需要一些帮助。非常感谢您!!

您需要包括您正在处理的行,例如

while(...) { 
   <button onclick="myFunction(<?php echo $id ?>);">....</button>
}

然后在调用 ajax 时使用该函数参数。