weixin_33726318 2013-11-08 19:51 采纳率: 0%
浏览 30

AJAX调用PHP复选框的问题

Having a problem with simple AJAX call that checks if checkbox is checked. At the moment, no matter if the checkbox is checked or not, it would print "not checked". I've tried changing "POST"/"GET" methods in he PHP code, but the result is same, i dont know why? any ideas?thanks!

      #test.html
      <html>
      <head>
      <script type="text/javascript">
        function load()
        {
           var xmlhttp;
           if (window.XMLHttpRequest)
           {// code for IE7+, Firefox, Chrome, Opera, Safari
             xmlhttp=new XMLHttpRequest();
           }
           else
           {// code for IE6, IE5
               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
           }
           xmlhttp.onreadystatechange=function()
           {
             if (xmlhttp.readyState==4 && xmlhttp.status==200)
             {
                 document.getElementById("div1").innerHTML=xmlhttp.responseText;
             }
          }
          xmlhttp.open("GET","checkbox.php",true);
          xmlhttp.send();
         }
        </script>
        </head>
        <body>

      <input type="checkbox" value="value1" name="check1"/>BOX 1</input>
      <br>
      <input type="checkbox" value="value2" name="check2">BOX 2</input>
      <br>
      <button type="button" onclick="load()">Run</button>
      <div id="div1"></div>

      </body>
      </html>


      #checkbox.php
      <?php
      if(isset($_GET['check1'])        
      {
         echo "checked";
      }
      else
      {
         echo "not checked";
      }   
      ?>
  • 写回答

2条回答 默认 最新

  • MAO-EYE 2013-11-08 19:59
    关注

    I don't see the point of using AJAX for this, can't you just check in javascript if the checkbox is checked or not ?

    Anyhow I'm more used to jQuery but it doesn't seem that you are sending any data, you need to test if the checkbox is checked in javascript and send the result in your request.

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划