我是AJAX的新手,无法运行php函数。
AJAX帖子请求正常运行,这是代码:
function thumbs(i) {
$('.thumbs-up' + String(i)).click(function(){
$(this).addClass('up');
$.ajax({
type:"POST",
url:"item.php",
data:'act=up&function' + String(i) + '=true&user=' + email,
success: function(){
}
});
});
for (var i = 1; i <= count; i++) {
thumbs(i);
}
以上作品,我收到了所有正确的值。
然后应该运行的PHP代码在这里:
for ($i = 1; $i <= $count; $i++) {
if ($_POST['function' . $i] == 'true') {
//code that should run but does not
}
}
count变量是相同的。这里有什么不对吗?
答案 0 :(得分:2)
您使用get
参数而不是发送post
参数。请参阅docs
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});