简体   繁体   中英

Can I use JS to load data from another file inside PHP/HTML code?

I have a PHP file which is returning data from a database. The data is being displayed as a table using HTML.

Now I have another '.php' file which is storing the data from an API. I was trying to integrate this data in the one being displayed using PHP.

PHP/HTML code

echo "
<div id='filter-result'>
    <table width='100%'>
        <tbody>
            <tr>
                <td rowspan='2'><img src={$row['image']} /></td>
                <td><h3>{$row['Name']}</h3></td>
                <td rowspan='1' style='font-size:20px'><div id='container-table'></div></td>
                <td rowspan='2'><a href={$row['link']} style='text-decoration:none;'>Buy Now</a></td>
            </tr>
            <tr>
                <td rowspan='1'>R</td>
                <td>Volume <br>
                    {$row['volume']}</td>
            </tr>
        </tbody>
    </table>
</div>";

JS code

<script>
    $('document').ready(function(){
        refreshData();
    })

    function refreshData() {
        $('#container-table').load("data.php", function(){
            setTimeout(refreshData, 10000);
        });
    }
</script>

your code is also working, kindly check path. normal way for load one page to another page is following method

$(".testtest").load('stack1.php');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM