XMLHttpRequest() は、作成後に XMLHttpRequest() をキャッシュしてメモリに保存するため、IE7 でキャッシュの問題が発生しているだけです。後続の変数を使用しても、 (最初の から)既にインスタンスがある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 は毎回空の参照を検出し、使用するたびに再作成する必要があります。
毎回作成および削除したくない場合は、XMLHTTPRequest でいくつかの HTTP ヘッダーを操作するだけです
xmlHttp_global.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
xmlHttp_global.setRequestHeader("Cache-Control", "no-cache");
ここで提案されているように
別の代替手段は次のとおりです。
GET メソッドよりも POST メソッドを使用する
xmlHttp_global.open("POST","checkFormDependency.action",false); xmlHttp_global.setRequestHeader("Content-type","application/x-www-form-urlencoded"); // または別のコンテンツ タイプ、それはあなた次第です xmlHttp_global.send("formName="+formName+"&applicationName="+appName);
クエリ文字列で「ダミー」変数を使用して、IE(7,6) のキャッシャーをバーストする
xmlHttp_global.open("GET","checkFormDependency.action formName="+formName+"&applicationName="+appName+"randomVar="+Math.Random(),false);
リンク