• 全部
...

关于IE8 创建XMLHttpRequest 的问题

买房动力十足 2011-11-07 11:52:50
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme() + "://"
  5. + request.getServerName() + ":" + request.getServerPort()
  6. + path + "/";
  7. %>

  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  9. <html>
  10. <head>
  11. <base href="<%=basePath%>">

  12. <title>My JSP 'MyJsp.jsp' starting page</title>

  13. <meta http-equiv="pragma" content="no-cache">
  14. <meta http-equiv="cache-control" content="no-cache">
  15. <meta http-equiv="expires" content="0">
  16. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  17. <meta http-equiv="description" content="This is my page">
  18. <!--
  19. <link rel="stylesheet" type="text/css" href="styles.css">
  20. -->
  21. <script type="text/javascript">
  22. function showHint() {
  23. var xmlhttp;

  24. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  25. xmlhttp = new XMLHttpRequest();
  26. } else {// code for IE6, IE5
  27. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  28. }
  29. xmlhttp.onreadystatechange = function() {
  30. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  31. document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
  32. }
  33. }
  34. xmlhttp.open("GET", "web/enterprise/pagetag.action", true);
  35. xmlhttp.send();
  36. setTimeout("showHint()",2000);
  37. }
  38. </script>
  39. </head>

  40. <body onload="showHint()">

  41. <p>

  42. <span id="txtHint"></span>
  43. </p>
  44. </body>
  45. </html>

最后一句 setTimeout("showHint()",2000);
是用来设置刷新的时间,这种写法在火狐、google浏览器中都可以运行,可以刷新。
但是在IE8中可以出结果,但是就是不能刷新,当使用IE8的兼容模式时菜可以自动的刷新,请问是什么原因导致的呢?
...全文
给本帖投票
571 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2011-11-07
  • 打赏
  • 举报
回复

xmlhttp.open("GET", "web/enterprise/pagetag.action?" + escape(new Date()), true);

hookee 2011-11-07
  • 打赏
  • 举报
回复
防止浏览器缓存
买房动力十足 2011-11-07
  • 打赏
  • 举报
回复
恩,确实可以了,请问这个是为什么呢?谢谢了先~[Quote=引用 1 楼 hookee 的回复:]
JScript code


xmlhttp.open("GET", "web/enterprise/pagetag.action?" + escape(new Date()), true);
[/Quote]

52,792

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧

手机看
关注公众号

关注公众号

客服 返回
顶部