复选框输入在chrome中根本不起作用。在其他浏览器中不起作用

时间:2014-03-13 22:58:46

标签: javascript php jquery html ajax

基本上我想要一个onClick的复选框来改变是否显示显式内容。我会正确使用代码

HTML(和PHP):

</form>
<?php if (login_check($mysqli) == true) {
    $username = $_SESSION['username']; 
    echo '
<form name="explicit">
<input type="checkbox" onClick="changeexplicit();" value="Filter Explicit Content"         id="explicitcheckbox" ' ;

    if (checkadult($mysqli,$username)!=1){echo "checked";}
    echo ' /> <label for="explicitcheckbox" class="explicit">Filter Explicit Content</label>
</form>';}?>

Jquery :(我把错误处理留空了,因为我没有意识到JQuery没有内置的弹出警报)

<script>
changeexplicit()
{
!(function($){
   $(function() {   
        $.post('includes/changeadult.php', $('form[name="explicit"]').serialize(),   function(data){

          data = $.parseJSON(data);

          if(data.success){
          window.location.reload(true);
          }
          else if(data.error){
          }
          else{
          }
        });
});
})(window.jQuery);
}
</script>


PHP:

<?php
include_once 'db_connect.php';
include_once 'functions.php';

sec_session_start(); // Our custom secure way of starting a PHP session.

$response = array();

if (login_check($mysqli) == true) {
$username=$_SESSION['username'];
        $result=mysqli_query($mysqli,'SELECT isAdult FROM members WHERE username =         "'.$username.'"');
    $userinfo = mysqli_fetch_array($result);
    $isAdult=$userinfo['isAdult'];
if ($isAdult==1)
{mysqli_query($mysqli,'UPDATE members SET isAdult=0 WHERE username="'.$username.'"');}
else{
    {mysqli_query($mysqli,'UPDATE members SET isAdult=1 WHERE username="'.$username.'"');}}

     $response['success'] = true;
}
else if(login_check($mysqli) == false) {
$response['error'] = true;
}
 echo json_encode($response);

2 个答案:

答案 0 :(得分:0)

<script>
function changeexplicit(){
    $.post('includes/changeadult.php', $('form[name="explicit"]').serialize(), function(data){
        data = $.parseJSON(data);
        if(data.success){
            window.location.reload(true);
        }else if(data.error){
        }else{}
    });
}
</script>

答案 1 :(得分:0)

尝试将onClick更改为onchange