我有这个code:
<script type="text/javascript">
function processForm() {
$.ajax( {
type: 'POST',
url: '/ajax/checkbox.php?name=foton',
data: { checked_box : $('input:checkbox:checked').val()},
success: function(data) {
$('#message').html(data);
}
} );
}
</script>
<input type="checkbox" name="foton" value="1" onclick="processForm()">
checkbox.php文件:
checkbox.php file:
$checkbox = intval($_POST['foton']);
if($checkbox == 1){
mysql_query("UPDATE users SET sekretessFoton = 1 WHERE userID = $memberID");
}else{
mysql_query("UPDATE users SET sekretessFoton = 0 WHERE userID = $memberID");
}
现在的问题是,我不得到$ _ POST ['福田']任意值 哪里不对?
The problem is that i dont get any value from $_POST['foton'] What is wrong?
感谢
编辑你的code的:
$.ajax( {
type: 'POST',
url: '/ajax/checkbox.php',
data: { foton : $('input:checkbox:checked').val()},
success: function(data) {
$('#message').html(data);
}
} );
/ajax/checkbox.php?name=foton
在这里,你有这就是所谓的名称
和值 $ _ GET
参数福田
。
在我的code你发送你的复选框中的值 $ _ POST
参数名为福田汽车
。
In my code you're sending the value of your checkbox in a $_POST
parameter called foton
.
您不必设置你的 $。阿贾克斯
URL查询字符串,当你指定的数据(而不是你的希望重定向到一个网页,其中将处理您的 $ _ GET
的部分参数)。
You don't have to set a query string in your $.ajax
url when you specify data (instead of you want to redirect to a page which will process your $_GET
parameters a part).