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)

don't want the p tag here

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);
    });
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!