每隔几秒钟从.php文件加载代码

时间:2022-10-28 01:24:29

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

我试图每3秒从sadrzaj.php加载代码。这是我的代码:

<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

解决了!我突然忘了包含jQuery。我现在正面对着! :d

6 个解决方案

#1


1  

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:

试试这个并查看开发人员JavaScript控制台(在Chrome / Chromium中按F12),看看是否有“调用”或任何错误消息:

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

#2


0  

 $(document).ready(function () {
             setInterval(function (e) {
             $('#sadrzaj').load('sadrzaj.php');
        }, 1000);
    });

#3


0  

You miss div end tag in your html code,

你错过了html代码中的div结束标记,

In javascript the code is :

在javascript中代码是:

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

If you use jquery library, the code is :

如果使用jquery库,代码为:

$(document).ready(function()
{
   setInterval( function()
   {
      ima_sta_novo();
   }, 3000);
});

#4


0  

try this with javascript

用javascript试试这个

<body onload="ima_sta_novo();">
<div id="sadrzaj">
    </div>
    <script>
         function ima_sta_novo(){
        window.location.href = "sadzraj.php";
    }
    setInterval(function(){ima_sta_novo()}, 3000);

    </script>
</body>

#5


0  

Just Close the div

只需关闭div

<div id="sadrzaj"></div>

seems all other things are ok..

似乎所有其他事情都没问题..

put an alert box inside the javascript method ima_sta_novo() for checking

在javascript方法ima_sta_novo()中放置一个警告框进行检查

#6


-1  

Replace http://*.com with the link to your page

将http://*.com替换为您网页的链接

<script type="text/javascript">
    setInterval(function(){window.location.replace("http://*.com")},3000);
</script>

This way you completely reload the page if you don't mind reloading the page this is a easy way to go.

这样,如果您不介意重新加载页面,则可以完全重新加载页面,这是一种简单的方法。

#1


1  

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:

试试这个并查看开发人员JavaScript控制台(在Chrome / Chromium中按F12),看看是否有“调用”或任何错误消息:

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

#2


0  

 $(document).ready(function () {
             setInterval(function (e) {
             $('#sadrzaj').load('sadrzaj.php');
        }, 1000);
    });

#3


0  

You miss div end tag in your html code,

你错过了html代码中的div结束标记,

In javascript the code is :

在javascript中代码是:

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

If you use jquery library, the code is :

如果使用jquery库,代码为:

$(document).ready(function()
{
   setInterval( function()
   {
      ima_sta_novo();
   }, 3000);
});

#4


0  

try this with javascript

用javascript试试这个

<body onload="ima_sta_novo();">
<div id="sadrzaj">
    </div>
    <script>
         function ima_sta_novo(){
        window.location.href = "sadzraj.php";
    }
    setInterval(function(){ima_sta_novo()}, 3000);

    </script>
</body>

#5


0  

Just Close the div

只需关闭div

<div id="sadrzaj"></div>

seems all other things are ok..

似乎所有其他事情都没问题..

put an alert box inside the javascript method ima_sta_novo() for checking

在javascript方法ima_sta_novo()中放置一个警告框进行检查

#6


-1  

Replace http://*.com with the link to your page

将http://*.com替换为您网页的链接

<script type="text/javascript">
    setInterval(function(){window.location.replace("http://*.com")},3000);
</script>

This way you completely reload the page if you don't mind reloading the page this is a easy way to go.

这样,如果您不介意重新加载页面,则可以完全重新加载页面,这是一种简单的方法。