我真的不知道为什么这不起作用!
<script src="js/jquery.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
function updateVAL()
{
var f = document.getElementById("nu");
var val=f.value;
alert(val); // it displays the value properly
$.post("getDATA.php", {id: val}); // I sent the variable with jquery
}
</script>
getDATA.php
$value=$_POST['id'];
echo $value;
当我访问 getDATA.php 以查看它是否已发送时,我得到以下信息:
Notice: Undefined index: id in C:\Users\dan...
为什么变量“id”没有设置?为什么没有传递到服务器?
如有任何帮助,我们将不胜感激:) 干杯,
丹。
最佳答案
参数是通过ajax发送的 - 因此这个js
脚本调用getDATA.php
并且$_POST['id']
被“看到” “仅在那时。
并且您尝试访问 getDATA.php
之后,并且通过 briwser 不发送 post
或 get
参数 - 所以您不会在那里看到这个参数。
您必须通过 js
脚本捕捉 echo
。看看这个演示:
$.post("test.php", { name: "John", time: "2pm" },
function(data) {
alert("Data Loaded: " + data);
});
关于php - 将变量传递到 php 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7239402/