donglvhe7591 2011-10-19 15:33
浏览 48
已采纳

AJAX只在IE中加载一次

I can not figure out why the following AJAX code will only load the information from my php page one time in IE, works in all other browsers with no problem.

   <script type="text/javascript">
var c=0;

function randomize(str)
{

if (str=="")
  {
  document.getElementById("dispeople").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("dispeople").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","randomize.php?q=" + Math.random(),false);
xmlhttp.send();

document.getElementById('txt').value=c;
c=c+1;
}

setInterval( "randomize()", 2000 );
</script>

I am fairly new to using AJAX and have researched this issue and implemented all the solutions I could find, any help would be greatly appreciated.

Update, 10/21/2011

I have checked out JQuery and implemented it and am still experiencing the same issue if anyone has any suggestions here is the code I am currently using:

<script type="text/javascript">
var c=0;

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
 });

   setInterval(function() {
     $.ajax({
     type: "GET",
     url: 'randomize.php?ck=' + (new Date()).getTime(), 
     cache: false,
        success: function(data) {

          $('#dispeople').html(data);
     }
     });
     },2000);


</script>

Thank you

  • 写回答

3条回答 默认 最新

  • dousao9569 2011-11-24 13:10
    关注

    I think your jquery code is fine. It happens due to ie browser caching. Try sending a random value with your request and return the time() from php side to see if it is actually calling the php script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)