April 9, 2012
jQuery load function and tables
Question by Syfaro
On my site, it displays a table of data.
I’ve got a link that will load another table of data from a URL.
$("#another").click(function() {
var newGeneration = $('<p />').load('another.php?cycle=' + i);
$('tbody').append(newGeneration);
i++;
});
Is there a way to get it so that it doesn’t add a p tag and just directly load the file into the tbody? I tried changing it to tr, but that just made trs inside of trs.
The code that displays another result
echo "<tr>";
echo "<td>" . $keys[$k] . "</td>";
echo "<td>" . $jobs[$k] . "</td>";
echo "</tr>";
What I don’t want to happen (like it is now)
Answer by Starx
I think its better to send a get request instead of complicating the use of load.
$("#another").click(function() {
$.get('another.php', { 'cycle' : i }, function(data) {
$('tbody').append(data);
});
});