check box value posting and jquery ajax
i have this scenario in my program, i'm printing a list of check boxes to my main page using below codes
<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>
after that i'm using the below code to get the process done using jquery ajax
$('#see').click(function(eve){
eve.preventDefault();
$.post('two.php', function(data) {
$('#results_of_interactions').html(data);
});
});
but i need to get the selected check box values inside my two.php(the files handling the processes of the above form) file in order to execute a sql query, but when i use this jquery approach the check box variables are not available at my two.php file, so my query is not properly executed and i can't get the results, how can i correct this issue?please suggest some thing to do, a modification to this or another approach?
regards, Rangana
That's because you have to manually prepare the data and send it along with your post request, it does not submit the form, it submits whatever you manually tell it to submit to 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');
});
精彩评论