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