我在网页上看到我的一个变量时遇到问题。这是我到目前为止所拥有的。
 $(document).ready(function() {
    $(function() {
        $("#CheckID").click(function() {
         // submit ajax job and display the result
         var id = '$("#ID").val()'      
            $.ajax({
                type: "POST",
                url: "test_wID.php",
                data: "id",
                success: function(data) {
                $('#rightselection').html(data)
                }
            });
        });
    });
});
这是我用来将输入到表单中的 ID 并将该 ID 用于 bash 脚本的 jquery 函数。
这里是php。
<?php
//Get the ID from the HTML form and use it with the check chunk script.
$id = $_POST['ID'];
if (is_null($id)){
        echo "$id is null";
}
echo "Selected test Game ID: ".$id;
//print shell_exec('/opt/bin/tester $id');
?>
我注释掉了脚本,因为变量返回 null,此时我只是想确保我得到了 ID。
为了完整起见,这里是我正在使用的表格。
print "<p><h3>ID: <input type=\"text\" id=\"ID\" /></h3></p>";
#print "<br>";
print "<p><button id=\"CheckID\">Check ID</button></p>";
当我单击按钮时,我在我的 div 中收到变量为空的消息。所以我的问题是我在声明中遗漏了什么吗?怎么是var id空的?
感谢您提供的任何帮助。