We help IT Professionals succeed at work.

Using JQuery to pull html table from external page?

brihol44
brihol44 asked
on
If I have a page called pagea.html and on that page I'm using jquery to pull ONLY the HTML table from another page pageb.html could I do that with JQuery and if so does anybody have an example of how one would do this?

pagea.html

JQuery call information...

pageb.html

<table id="myTable">
<tr><td>My Info</td></tr>
</table>
Comment
Watch Question

ok what you have to understand is that what jquery will pull from the other page is everything that would have been output to the browser had you just pulled up the other page up by itself.
So if all that the other page has on it is the table then it should work just fine, if not then you are going to get more than you are planning and you would end up having to parse through the response before using it one the first page.
Assuming that all you have on the other html page is the table itself then all you should need is a function like this.
 
    $.get("table.html",function(data){
        $("ElementThatIsToBeFilled").html(data);
    });
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
$("#where_you_want_to_see_the_table").load("pageb.html #myTable");


pagea.html you have this somewhere :

<div id="where_you_want_to_see_the_table"></div>

please note : jQuery load pageb.html entirely

http://api.jquery.com/load/
(Loading Page Fragments)
Nice, I didn't realize that load can do parts of the called page instead of the whole thing. That is really just what this question seems to be asking for.
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
>Nice, I didn't realize that load can do parts of the called page instead of the whole thing.

it's just a shorcut of $.get, it need to load the full page like any other ajax call

Explore More ContentExplore courses, solutions, and other research materials related to this topic.