您只是在IE7中存在緩存問題,因爲它在創建XMLHttpRequest()並將其存儲在其內存中後緩存它。即使有後繼xmlhttp=new XMLHttpRequest();
該變量也沒有得到任何分配,因爲它已經有一個實例(從您的第一個xmlhttp=new XMLHttpRequest();
開始)。
你需要做的是無效和摧毀每次使用後您的XMLHttpRequest請求。
首次創建的XMLHttpRequest(用於MSIE 7)所示:
function createXMLHttpRequest(){
var xmlHttp = null;
if(typeof XMLHttpRequest != "undefined"){
xmlHttp = new XMLHttpRequest();
}
else if(typeof window.ActiveXObject != "undefined"){
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
}
catch(e){
try {
xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e){
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
xmlHttp = null;
}
}
}
}
return xmlHttp;
}
所以您要使用的功能,每次創建它。
function checkDependencyFormFilledStatus(appName,formName){
if(xmlHttp_global){
xmlHttp_global.abort(); // abort the current request if there's one
}
// Create the object each time a call is about to be made
xmlHttp_global = createXMLHttpRequest();
if(xmlHttp_global){
xmlHttp_global.onreadystatechange = myCallbackFunction; // make you callback thing here
xmlHttp_global.open("GET","checkFormDependency.action formName="+formName+"&applicationName="+appName,false);
xmlHttp_global.send(null);
}
}
在回調(「onreadystatechange的」功能),你使用它
function myCallbackFunction()
{
if(xmlHttp_global && xmlHttp_global.readyState == 4){
//do your thing here and ... or nothing
var dependentFormEmptyStatus = Ext.JSON.decode(xmlhttp.responseText);
alert(xmlhttp.responseText); // like this for example?
xmlHttp_global = null; //delete your XMLHTTPRequest
}
}
所以IE 7將每次找到一個空引用刪除後它,將有必要再重新創建每次使用。
,如果你不希望創建和刪除eacht時候你只是一些HTTP報頭在你的XMLHTTPRequest發揮
xmlHttp_global.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
xmlHttp_global.setRequestHeader("Cache-Control", "no-cache");
像建議here
另一種替代方案包括:
通過GET方法使用POST方法
xmlHttp_global.open(「POST」,「checkFormDependency.action」,false); xmlHttp_global.setRequestHeader(「Content-type」,「application/x-www-form-urlencoded」); //或其他內容類型,由您決定 xmlHttp_global。發送(「formName =」+ formName +「& applicationName =」+ appName);
使用在查詢字符串一個 「虛擬」 可變爆出IE的cacher的(7,6)
xmlHttp_global.open( 「GET」, 「checkFormDependency.action表格名稱=」 +表格名稱+」 & applicationName =「+ appName +」randomVar =「+ Math.Random(),false);
鏈接
它的工作..謝謝你...我轉換的開放調用xmlhttp.open( 「GET」,「checkFormDependency.action?表格名稱= 「+ formName +」&applicationName =「+ appName +」&timeStamp =「+ new Date()。getTime(),false); – Shashwat 2012-07-13 10:45:54