我遇到了在网页上看到我的一个变量的问题。这是我到目前为止。jquery函数中的变量为空
$(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
为空是怎么回事?
感谢您提供任何帮助。
了解javascript的。请。 –
并学会清理你传递给shell命令的输入(['escapeshellarg()'](http://php.net/escapeshellarg)) - 即使它现在已被注释掉。 – ThiefMaster