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条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站