如何从其他.php链接每5秒自动刷新SRC链接一次



如何自动刷新SRC链接一次每5秒链接到img链接到其他.php链接到index.php src link ??

in index.php

<img id="img1" class="imgNews" src =https://example.com/car.jpg">

in other.php

<span id =link1>https://example.com/other.jpg</span>

index.php

的预期结果
<img id="img1" class="imgNews" src =https://example.com/other.jpg">
<div id="loader">
  <img class="imgNews" src="https://example.com/car.jpg">
</div>
<script src="//www.antradar.com/nano.js"></script>
<script>
setInterval(function(){
    ajxpgn('loader','other.php?');
},5000);
</script>

更改您的其他.php内容以直接显示图像:

<img src="some_other_image.jpg">

index.php

setInterval(function(){
$.ajax({
    url:"other.php",  
    dataType : 'html',
    success:function(response) {
      $('#img1').prop('src', $(response).filter('#link1').html());
    }
  });
},5000);

您可以使用过滤器从Ajax返回的html获取元素。

最新更新