2011-01-22 36 views
0

我在我的節目這種情況下,我使用下面的代碼複選框值發佈和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

回答

1

那是因爲你必須手動準備數據,並與您的文章請求一起發送,它不提交表單,它提交無論你手動告訴它提交給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