Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load code from .php file every few seconds [closed]

I'm trying to load code from sadrzaj.php every 3 seconds. This is my code:

<body onload="ima_sta_novo()">
<div id="sadrzaj">
</body>

<script type="text/javascript">
    function ima_sta_novo(){
        $('#sadrzaj').load('sadrzaj.php');

    }
    setInterval(function(){ima_sta_novo()}, 3000);

</script>

But, it isn't loading anything. What am I doing wrong?

SOLVED! I suddenly forgot to include jQuery. I'm facedesking now! :D

like image 633
Karlo Sintic Avatar asked Aug 04 '26 15:08

Karlo Sintic


1 Answers

Try this and have a look at the developer JavaScript console (press F12 in Chrome/Chromium) and see if the word "invoked" or any error messages happen:

 <html>
    <head>
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    </head>
    <body>
        <div id="sadrzaj"></div>

        <script>

            function setTimer() {
                setInterval(function(){
                    console.log('invoked');
                    $('#sadrzaj').load('sadrzaj.php');

                }, 3000);
            }


            $(document).ready(setTimer);
        </script>
    </body>
</html>
like image 179
thomas.mc.work Avatar answered Aug 06 '26 03:08

thomas.mc.work