阿贾克斯后,并得到复选框值 [英] Ajax post and get checkbox value
本文介绍了阿贾克斯后,并得到复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个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).
这篇关于阿贾克斯后,并得到复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文