0

在我的应用程序中,为了避免重复的组名,我试图通过 AJAX 调用验证用户输入的值。但我没有收到预期的 responseText,但我从缓存接收 responseText。JS 文件:try{ if (window.ActiveXObject) //IE var xhr = new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) //其他 var xhr = new XMLHttpRequest(); else alert("您的浏览器不支持 AJAX"); }catch(e){alert("创建 xmlhttpresponse 时出错:"+e);}

    escName= document.forms(0).txtEscalationName.value;
    escId = document.forms(0).hidGroupId.value;

    urlParam = "escName=" +escName +"&escCode=" +escId;
    alert(".."+urlParam);       
    xhr.open("GET", "/myapp/jsp/main/escalationNameCheck.jsp?"+urlParam+"&ran="+Math.random() ,true);

xhr.setRequestHeader("Cache-Control","no-cache");
 xhr.setRequestHeader("Pragma","no-cache"); 
xhr.onreadystatechange = function() {

    if (xhr.readyState == 4)
    {               
        if (xhr.status == 200)
        {   
            if (xhr.responseText != null) 
            {   

            alert(document.getElementById("escalationNameValidate"));

                try{
                var populate = document.getElementById("escalationNameValidate");

                populate.innerHTML = xhr.responseText;
                }catch(e){

                alert("ERROR!...."+e);
            }
            }
            else
            {
                alert("Failed to receive JSP file from the server - file not found.");
                return false;
            }

        }
        else
            alert("Error code " + xhr.status + " received: " + xhr.statusText);
    } else
    alert("not ready");
} 
xhr.send(null); 

在这里引用后:responseText - XMLHttpRequest 我尝试过提及下面的事件,但它给出了异常说目标为空或不是对象。xhr.onreadystatechange = 函数(事件){ var xhr = event.target; if (xhr.readyState == 4) { alert("first if");
if (xhr.status == 200) {alert("second if");
if (xhr.responseText != null) {alert("第三个 if"+xhr.responseText);

            alert(document.getElementById("escalationNameValidate"));

                try{
                var populate = document.getElementById("escalationNameValidate");
                alert("11");
                alert("pop.."+populate.innerHTML);
                populate.innerHTML = xhr.responseText;
                }catch(e){

                alert("ERROR!.xhr..."+e);
            }
            }
            else
            {
                alert("Failed to receive JSP file from the server - file not found.");
                return false;
            }
            alert("escNameDuplicate"+document.getElementById("escNameDuplicate"));
        }
        else
            alert("Error code " + xhr.status + " received: " + xhr.statusText);
    } else
    alert("not ready");
} 

所以我尝试了 1. 在 requestHeader 中将缓存控制作为无缓存 2. 在定义时使用 var xhr 将 xhr 作为局部变量。3.在onreadystatechange函数中也指出了事件实例。浏览器版本:IE7

请协助。问候, Nidhya

4

1 回答 1

0

我通过修改 IE 设置中的几个选项来完成这项工作。即使我关闭浏览器并再次打开 IE,我的响应也被缓存在浏览器中。所以,我所做的是,转到工具 - > Internet选项选择浏览器历史记录下的设置选择“检查存储页面的较新版本:”下的“每次我访问网页”保存设置。

希望它能帮助像我这样的人。

于 2013-09-05T05:42:08.597 回答