使用Jquery刷新除单个图像之外的所有页面

Using Jquery to refresh all of a page but a single image

本文关键字:刷新 Jquery 单个 图像 使用      更新时间:2023-09-26

我已经阅读了如何使用jquery刷新单个div,但我有一个主要基于表和更新元素的网页。我目前有一个单独的脚本,每1.5秒刷新一次网页,但我的Web_Main文件中有一个静态图像,每次页面刷新时都会闪烁,所以我想在Web_Run文件中使用jquery将该图像从页面刷新中排除。我已经将jquery-1.11.2.min.js文件包含在我的目录文件夹中,并有引用它的头,但我不熟悉jquery,也不知道如何为除图像刷新之外的所有内容创建div,以及我应该将其放在Web_Main脚本还是Web_Run脚本中。

我的Web_Main设置为:

<div class ="refreshpage"> 

<!-- Rest of page content needing refreshed above --> </div>
<div class = "staticpic">
 <img src="picdrawing.png" height="130px" width="99.8%">
 </div> 
 <div class ="refreshpage"> 
<!-- Rest of page content needing refreshed below--> </div>

我的Web_Run页面

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style type="text/css">
</style>
<script>
function showCustomer(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari     php<!-- include('test.php');--> ?>
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","Web_Main.php",true);
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 01 Jan 2000 00:00:00 GMT" );
xmlhttp.send(null);
//showCustomer('ALFKI');
setTimeout(function(){showCustomer('load')}, 1500);
}
</script>
</head>
<body onLoad="showCustomer('Load')">
<div id="txtHint"></div>
</body>
</html>

为什么不尝试使用缓存来缓存静态图像?它仍然会与页面一起"加载",但它不会再闪烁,因为它将立即从缓存中提供服务。

确实没有办法刷新除div或图像之外的所有内容,但在页面上缓存内容只是出于这个原因。因此,您将不必重新加载静态内容。