【问题标题】:Webpage update without refresh not working没有刷新的网页更新不起作用
【发布时间】:2012-10-16 02:51:54
【问题描述】:

我正在尝试在不刷新的情况下进行页面更新,并且我已经阅读了一些教程并提出了以下代码。但是,它似乎不起作用。当您按下按钮时,似乎什么也没有发生。

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');
?>

【问题讨论】:

    标签: javascript jquery ajax refresh partial-page-refresh


    【解决方案1】:

    您必须与其他脚本分开声明您的 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>
    

    【讨论】:

    • 我不完全确定你的意思是 IoQ?
    • 注意到你的脚本头了吗?
    • 刚刚试过了,还是不行。我取消了警报弹出窗口的注释,它没有显示提示它不会触发。更新问题以显示新代码
    • 由于语法错误,它不起作用.. 还删除文本“取消注释以了解您的脚本是否有效”或将您的 jquery 链接替换为 src='code.jquery.com/jquery-latest.pack.js'
    猜你喜欢
    • 2015-06-08
    • 2018-02-02
    • 2018-06-14
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 2017-07-18
    • 1970-01-01
    相关资源
    最近更新 更多