复选框值发布和jQuery AJAX

问题描述:

我在我的节目这种情况下,我使用下面的代码复选框值发布和jQuery AJAX

<form action="two.php" method="post"> 
    <div id="option_box" style="width: 250px; height: 400px; overflow: scroll;"> 
      <?php 
      $sql = "SELECT * FROM gene_names ORDER BY name"; 
      $result = $db->query($sql); 
      $counter = 0; 
      echo "<table border=\"0\">"; 
      while ($row = $result->fetch()) { 
       $output[] = "<tr>"; 
       $output[] = "<td>"; 
       $output[] = "<input type=\"checkbox\" value=\"".$row['name']."\" name=\"things[]\" id=\"ran\"/>"; 
       $output[] = " ";  
       $output[] = $row['name']; 
           $output[] = "</td>"; 
       $output[] = "</tr>";  
       $counter++; 
      } 
      echo join('',$output); 
      echo "</table>"; 
     ?> 
    </div> 
    <input type="submit" value="See Interactions" name="see" id="see"/> 
</form> 

之后我用下面的代码打印的复选框列表,以我的主页获得使用jQuery AJAX

 $('#see').click(function(eve){ 
       eve.preventDefault(); 
       $.post('two.php', function(data) { 
         $('#results_of_interactions').html(data); 
       }); 
    }); 

完成的过程,但我需要得到以执行一个SQL查询我two.php里面的复选框选中值文件(处理上述表格的过程中的文件),但是当我使用这个jquery方法复选框变量不可用在我的two.php文件,所以我的查询是没有正确执行,我无法得到结果,我该如何纠正这个问题?请建议一些事情要做,对这个或另一种方法进行修改?

问候, Rangana

那是因为你必须手动准备数据,并与您的文章请求一起发送,它不提交表单,它提交无论你手动告诉它提交给two.php

$('#see').click(function(eve){ 
    eve.preventDefault(); 

    //serialize form data to be sent with request 
    var data = $('form').serialize(); 

    //send request with 'data' 
    $.post('two.php', data, function(data) { 
     $('#results_of_interactions').html(data); 
    },'json'); 
}); 
+0

非常感谢您的回答jondavidjohn! – 2011-01-23 05:05:25