I am trying to create a table that would change its content based on user input. The table displays some data from a database; it starts the selection starting with a given calendar date that defaults to current date. I took a look at jQuery - Reload table. Then I made a PHP script that generates the table, gentable.php. When I try using a button with the event:
$(document).ready(function(){
$("#maket").click(function(){
$("#mytable").开发者_如何学JAVAload("tablegen.php");
});
});
everithing goes fine(the div mytable is filled with the generated table). Now I want to send some input data to the PHP script in order to generate the table starting with a different date. This is what I tried:
$(document).ready(function() {
$('#myform').ajaxForm({
target: '#mytable',
success: function() {
$("#mytable").load("tablegen.php");
}
});
});
And added in the PHP script the following lines:
if (isset($_POST['textf'])){
$value = $_POST['textf'];
}else{
$value = '2010/11/28';
}
genTable($value);
Unfortunatelly, this opens a new page that contains the table with beginning date not modified. What am I doing wrong? I also tried using .post but had no successful results. Please help. Thanks a lot. Diana
Try the following:
$.ajax({
type: 'POST',
url: 'gentable.php',
data: {textf: **INSERT_VALUE_HERE**},
dataType: 'html',
success: function(data, txtStatus, xmlHttpReq){
$('#mytable').html(data);
}
});
http://api.jquery.com/jQuery.ajax/
$.ajax({
type: "POST",
url: "tablegen.php",
data: "textf=whateveryouwant",
success: function(msg){
alert( "Data back: " + msg );
}
});
Thank you for your answers. For some reason, I didn't manage to use $.ajax
. Instead, I passed the values I needed to the load function, like this:
$(document).ready(function(){
$("#maket").click(function(){
$("#mytable").load("gentabel.php", {textf: $('#textf').val()});
});
});
The behavior is what I wanted. :)
精彩评论