如何使用AJAX将复选框值发布到php脚本?

时间:2011-09-20 23:33:56

标签: php jquery html css

如何使用以下内容发送到php页面,将mysql中每个复选框的值插入新行或更新现有列

<script language="javascript" type="text/javascript">// <![CDATA[
 var $n = jQuery.noConflict(); //Jquery no conflict 

     $n("#btnsubmit").click(function() {

             var allChkbox=$n('input[name=cats[]]');

              jQuery.each(allChkbox, function(i, singlecheckbox) {
                alert(singlecheckbox.value+" is "+ singlecheckbox.value);
             });


        });
 // ]]></script>

1 个答案:

答案 0 :(得分:0)

 var $n = jQuery.noConflict(); //Jquery no conflict 

     $n("#btnsubmit").click(function() {

             var allChkbox=$n('input[name=cats[]]');
              var data = [];
              jQuery.each(allChkbox, function(i, singlecheckbox) {
                data[singlecheckbox.value] = singlecheckbox.value; // this line is strange, the index seems not be singlecheckbox.value
                // alert(singlecheckbox.value+" is "+ singlecheckbox.value);
             });
              $.ajax({type:"GET", url: "test.php", data: data,
success:function(records){}, error: function(request, status, err){}});


        });

test.php将通过get获得请求。