jQuery-在div上循环加载多个外部html

时间:2018-09-27 06:41:52

标签: javascript php jquery

我正在寻找解决方案,但是我找不到任何适当的建议。

我的目标是在同一页面(在div内)循环不同的外部url,而不是使用header选项循环页面。这是我当前在div中显示一个外部页面的代码:

<script>
   $(document).ready(function(){
    function loadlink(){
        $('#tableHolder').load('read_data_from_page_one?v=1',function () {
             $(this).unwrap();
        });
    }

    loadlink(); // This will run on page load
    setInterval(function(){
        loadlink() // this will run after every 5 seconds
    }, 30000);
    });
</script>

所以30秒钟后,我的div“ tableholder”被刷新了,没关系。现在,我想在同一div中5分钟后添加另一个外部页面,然后在5分钟后再次添加另一个外部页面。作为我的第一个外部页面,它们需要每30秒刷新一次。之后,它需要再次加载第一个外部页面。

因此基本上可以在div中循环访问外部内容。那可能吗?

另一种解决方案是通过页眉选项循环页面:

<?php header("Refresh: 300; URL=read_data_from_page_two.php"); ?>

但是我不想要那个。有什么建议么?

最诚挚的问候,米斯科

3 个答案:

答案 0 :(得分:0)

这或多或少是您的意思?可以每 public async Task<IActionResult> Index() { if (!await _roleManager.RoleExistsAsync("Admin")) { await _roleManager.CreateAsync(new IdentityRole("Admin")); } var user = await _userManager.FindByEmailAsync("danny.meier@tpcag.ch"); if (!await _userManager.IsInRoleAsync(user, "Admin")) { await _userManager.AddToRoleAsync(user, "Admin"); await _userManager.UpdateAsync(user); } return View(); } [Authorize] public IActionResult About() { ViewData["Message"] = "Your application description page."; return View(); } [Authorize(Roles = "Admin")] public IActionResult Contact() { ViewData["Message"] = "Your contact page."; return View(); } 秒循环显示一次的链接数组,并在所有链接都显示后重复出现吗?

n

答案 1 :(得分:0)

如果页面已编号,则简单的计数器就可以了:

$(document).ready(function(){
    var counter = 1, // current page
        max = 3; // last page
    function loadlink(){
        $('#tableHolder').load('read_data_from_page_one?v='+counter,function () {
            $(this).unwrap();
        });
    }

    loadlink(); // This will run on page load
    setInterval(loadlink, 30000); // this will run after every 30 seconds

    setInterval(function(){
        if(++counter > max){ // next page
            counter = 1; // back to start
        }
    }, 5000000); // 5 min interval
});

答案 2 :(得分:0)

$(document).ready(function(){
    function loadlink(x = 1){
        $('#tableHolder').load('read_data_from_page_one?v='+x,function () {
             $(this).unwrap();
        });
    }

    loadlink(); // This will run on page load

    var x=1;
    setInterval(function(){
        x++
        loadlink(x); // this will run after every 5 seconds
    }, 30000);
    });