【发布时间】:2010-10-31 05:57:15
【问题描述】:
我有一个简单的 AJAX 函数将对象的 id 发送到 php 页面
我的函数如下所示:
$(function(){
$("a.vote").click(function(){
//get the id
the_id = $(this).attr('id');
alert(the_id);
//ajax post
$.ajax({
type: "POST",
data: "?id="+the_id,
url: "vote.php",
success: function(msg)
{
$("span#message"+the_id).html(msg);
}
});
});
});
我的 vote.php 看起来像这样:
session_start();
if(isset($_SESSION['user'])) {
// db setup removed
// insert vote into db
$q = "UPDATE votes SET vote = vote + 1 WHERE id = " . $_POST['id'];
mysql_query($q);
echo "You sent " . $_POST['id'];
}
当我执行我的 AJAX 函数时,vote.php 似乎永远不会运行
我知道我的 AJAX 函数被正确调用,因为 alert(the_id);正在弹出正确的 ID。
我知道我的 vote.php 运行正常,因为我可以运行带有名为“id”的文本框的 HTML 方法="post",它会正确更新数据库。
谁能看出问题所在?
谢谢
【问题讨论】:
标签: php javascript jquery ajax