??yy 2020-04-03 08:53 采纳率: 0%
浏览 96

如何使用AJAX刷新div?

I know there are many entries about this topic but I dont get my code to work. I build a div container (this is the div I want to refresh every second) which includes 3 other div containers.

My code so far: index.php

<div id="ajax">
   <div class="row d-flex align-items-center">
      <div class="showPGF"> 
         <?php
            $controller->getEntries();
         ?>
      </div>
   </div>

   <div class="row d-flex align-items-center">
      <div class="showNGi_sample"> 
         <?php
            $controller->getUsers();
         ?>
      </div>
   </div>

   <br>

   <div class="row d-flex align-items-center">
      <div class="showNGi_sample"> 
         <?php
            $controller->getPGFEntries();
         ?>
      </div>
   </div>
</div>

script.js

$(document).ready(function () {

function ajax(){
        $('#ajax').load('index.php',function() {
            $(this).unwrap();
        });
    }

    ajax(); // This will run on page load
    setInterval(function(){
        ajax() // this will run after every 1 seconds
    }, 1000);

}

I want to get the DIV with the "ajax" id to get reload every second. Because I want to get always the current Entries/Users from my database (execute the php call every second). But currently it dont refresh and I need to press F5 to get the new entries shown.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C# datagridview 栏位进度
    • ¥15 vue3页面el-table页面数据过多
    • ¥100 vue3中融入gRPC-web
    • ¥15 kali环境运行volatility分析android内存文件,缺profile
    • ¥15 写uniapp时遇到的问题
    • ¥15 vs 2008 安装遇到问题
    • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
    • ¥15 找一个网络防御专家,外包的
    • ¥100 能不能让两张不同的图片md5值一样,(有尝)
    • ¥15 informer代码训练自己的数据集,改参数怎么改