Ajax到PHP,不更新?

Ajax到PHP,不更新?,php,ajax,Php,Ajax,这是我的index.php文件: <script type="text/javascript"> function addHit(str){ $.post("http://www.site.com/addclick.php", { id: str }) }; </script> <a href="javascript:;" onClick="addHit('928'); return false;">update ID 928 with 1 clic

这是我的index.php文件:

<script type="text/javascript">
function addHit(str){
    $.post("http://www.site.com/addclick.php", { id: str })
};
</script>

<a href="javascript:;" onClick="addHit('928'); return false;">update ID 928 with 1 click</a>
如果我有
其中id='1'
它会完美地更新
第928行,但是当它被设置为post变量时,它不会。我唯一能想到的是ajax调用没有正确解析ID


这有什么问题?

不是100%确定,但可能是因为在jquery中,您没有将id像这样引起来:

$.post("http://www.site.com/addclick.php", { 'id': str })
它考虑到您的id是一个变量,而不是变量的名称


希望有帮助。

为什么不在盲目地将$u POST插入数据库之前检查一下它是什么?我可以编写一个脚本来设置
id='Robert\';删除表学生--
并删除数据库

$id = intval($_POST['id']);
$sql = "UPDATE `table` SET x=x+1 WHERE id=$id";
$result = mysql_query($sql);
if ($result === FALSE) {
    die("query failed: " . mysql_error());
}

它是否在
var_dump($\u POST)
中?我建议不要使用/addclick.php,我以前也有同样的问题。$.POST(“/addclick.php”,{id:str})或$.POST(“addclick.php”,{id:str})这不是php问题,我没有发布真正的php代码,这是一个例子。最重要的是,这是开发,而不是网站上的工作脚本。
$id = intval($_POST['id']);
$sql = "UPDATE `table` SET x=x+1 WHERE id=$id";
$result = mysql_query($sql);
if ($result === FALSE) {
    die("query failed: " . mysql_error());
}