日期:2014-05-16  浏览次数:20678 次

关于IE8 创建XMLHttpRequest 的问题 - Web 开发 / Ajax
HTML code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

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

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

        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
        <script type="text/javascript">
function showHint() {
    var xmlhttp;
    
    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("txtHint").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "web/enterprise/pagetag.action", true);
    xmlhttp.send();
    setTimeout("showHint()",2000);
}
</script>
    </head>

    <body onload="showHint()">
     
        <p>
         
            <span id="txtHint"></span>
        </p>
    </body>
</html>

最后一句 setTimeout("showHint()",2000);
 是用来设置刷新的时间,这种写法在火狐、google浏览器中都可以运行,可以刷新。
但是在IE8中可以出结果,但是就是不能刷新,当使用IE8的兼容模式时菜可以自动的刷新,请问是什么原因导致的呢?

------解决方案--------------------
JScript code

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

------解决方案--------------------
防止浏览器缓存