繁体   English   中英

没有刷新的网页更新无法正常工作

[英]Webpage update without refresh not working

我正在玩一个没有刷新的页面更新,我已经阅读了一些教程,并提出了以下代码。 但它似乎没有起作用。 当你按下按钮时,似乎什么也没发生。

Index.php代码

    <!DOCTYPE html>
<html>
    <head>

        <script type="text/javascript" src="jquery.js"></script>

        <script>
                function updateShouts()
                {                
                    $('#refresh').load('update.php');
                    alert('it works!'); uncomment this to know if your script works
                } 
        </script>

    </head>

    <body>

        <div id="refresh">
            <?php
            include('update.php');
            ?>
            <button onclick="updateShouts()">Try it</button>

        </div>


    </body>

</html>

update.php代码

<?php
print strftime('%c');
?>

您必须将jquery链接与其他脚本分开声明

<script type="text/javascript" src="jquery.js"></script>

<script>
        function updateShouts()
        {                
            $('#refresh').load('update.php');
            //alert('it works!'); uncomment this to know if your script works
        } 
</script>

或者您可以使用更新的在线jquery库

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>

    <script>
        function updateShouts()
        {                
            $('#refresh').load('update.php');
            //alert('it works!'); uncomment this to know if your script works
        } 
    </script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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