0

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

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

1 回答 1

2

您必须与其他脚本分开声明您的 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>
于 2012-10-16T03:04:47.393 回答