[英]Call PHP function from Ajax
我是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
}
}
计数变量相同。 这里有什么问题吗?
您使用的是get
参数,而不是发送post
参数。 请参阅文档中的示例
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.