deviloper
deviloper

Reputation: 7240

loading external html file using jquery and accessing it content

I need to access some TD values in a TABLE that is in another HTML file. I am not really sure what way helps me get a working solution for this. Currently I want to access it using jquery. All I imagine for solving this issue is to load the whole external HTML file into a DIV in my main file and seek through the TDs to find my favorite one and print its content to my main TABLE TD. I do not seem to be able to figure it out. please help me with this! My main PHP file:

<?php
...
...
$loading_transmitter = $_POST['transmitter']; 
?> 
<script>  
$("#result").load('<?php echo $loading_transmitter; ?>',function(){
    var main_proc_temp = $(table:nth-child(2).tr:nth-child(1).td:nth-child(3)).text();#table loaded from the external file
    alert(main_proc_temp);#it should alert: "OK" but alets: "Undefined"
});
</script>

Is the content of the loaded file available this way? Because after loading it on the page (which goes well), I checked the source code and found out that the result div is yet empty.

Upvotes: 0

Views: 317

Answers (2)

jlewkovich
jlewkovich

Reputation: 2775

If you're using PHP, can you not write these values to a database as they change and access them that way?

Upvotes: 0

Rohan Kumar
Rohan Kumar

Reputation: 40639

I think you don't have tr and td class so remove the . from the selectors then check.

Also you should find your table in your responselike,

like,

$("#result").load('<?php echo $loading_transmitter; ?>',function(data){
    var main_proc_temp = $(data).find('table:nth-child(2) tr:nth-child(1) td:nth-child(3)').text();
    alert(main_proc_temp);
});

Upvotes: 1

Related Questions