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 に答える