简体   繁体   English

JQuery仅重新加载div数据

[英]JQuery Reload div data Only

I am new to JQuery and facing an issue while refreshing div using following script我是 JQuery 的新手,在使用以下脚本刷新 div 时遇到问题

 < script > $(document).ready( function() { setInterval(function() { $("#dbq").load("dbqtest.php"); }, 10000); //Delay here = 10 sec }); </script>
 <?php echo '<section class="col-lg-6" id="dbq">'; echo '<p>My Section </p>'; echo '</section>'; ?>

The section i am trying to refresh is declared as below我试图刷新的部分声明如下

The problem i am facing is that whenever the page loads for the first time, table from "dbqtest.php" is not visible for 1st 10 seconds.我面临的问题是,每当第一次加载页面时,“dbqtest.php”中的表在第 10 秒内不可见。 and My section stays there even after loading data from "dbqtest.php"即使从“dbqtest.php”加载数据后,我的部分仍然存在

You need a wrapper for reloading section .您需要一个包装器来重新加载section Somthing like this must work:像这样的事情必须工作:

<script>
 $(document).ready(
 function() {
  setInterval(function() {
   $("#dbq-wrapper").load("dbqtest.php");
  }, 10000); //Delay here = 10 sec
 });
</script>

And the HTML:和 HTML:

<div id="dbq-wrapper">
 <section class="col-lg-6" id="dbq">
  <p>My Section </p>
 </section>
</div>

Hoever you can use div inside section and reload data to that and use section as parent, anyway you need wrapper.但是,您可以在section内使用div并将数据重新加载到该section并使用section作为父项,无论如何您都需要包装器。


As you want to the first time load without delay, the solution is somthing like this:由于您想第一次立即加载,因此解决方案如下:

< script >
    function dbqLoader {
        $("#dbq").load("dbqtest.php");
    }

    $(document).ready(function() {
            dbqLoader(); // for first time.
            function() {
                setInterval(function() {dbqLoader();}, 10000); // Loop with Delay
            });  
    });
</script>

This has to be it:必须是这样:

<script>
    $(document).ready(function() {
        $("#dbq").load("dbqtest.php");
        setInterval(function() {
               $("#dbq").load("dbqtest.php");
        }, 10000); 
    });
</script>

It's very similar to M.Abooali's answer but I've fixed some issues and minimised it.它与 M.Abooali 的回答非常相似,但我已经解决了一些问题并将其最小化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM