2011-09-20 64 views
-1

如何使用以下发送给一个PHP页面的每个在MySQL中的复选框的值是插入新行或更新exisiting列如何使用AJAX将复选框值发布到php脚本?

<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> 

回答

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接收请求。