Question

I'm playing around with making a page update without refreshing and I've read some tutorials and came up with the following code. However it doesn't seem to be working. When you press the button, nothing seems to happen.

Index.php code

    <!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 code

<?php
print strftime('%c');
?>
Était-ce utile?

La solution

You have to declare your jquery link separately from your other script

<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>

or you can use an updated online jquery library

<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top