2012-04-30 8 views
1

IE 7を持つユーザーのために回避策を見つけようとしています。基本的にクライアントサイドのJavaScriptアプリケーションでは、以下のコードはnode.jsを実行するサーバーにhttprequestを、クライアントがIE8を持っていてもIE7ではうまくいかない場合は、正常な接続が得られます。思考?ノードサーバーへのHTTPRequestはIE 8では機能しますが、IE 7では機能しません。

var myxmlhttp; 
doRequest(); 

function doRequest() { 
    var url = "http://someserver:8000/" + username; 
    myxmlhttp = CreateXmlHttpReq(resultHandler); 

    if (myxmlhttp) { 
     XmlHttpGET(myxmlhttp, url); 
    } else { 
     alert("An error occured while attempting to process your request."); 
     // provide an alternative here that does not use XMLHttpRequest 
    } 
} 

function resultHandler() { 
    // request is 'ready' 
    if (myxmlhttp.readyState == 4) { 
     // success 
     if (myxmlhttp.status == 200) { 
      alert("Success!"); 
      // myxmlhttp.responseText is the content that was received 
     } else { 
      alert("There was a problem retrieving the data:\n" + req.status.text); 
     } 
    } 
} 

function CreateXmlHttpReq(handler) { 
    var xmlhttp = null; 

    if (window.XMLHttpRequest) { 
     xmlhttp = new XMLHttpRequest(); 
    } else if (window.ActiveXObject) { 
     // users with activeX off 
     try { 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     } catch (e) {} 
    } 

    if (xmlhttp) xmlhttp.onreadystatechange = handler; 

    return xmlhttp; 
} 

// XMLHttp send GEt request 
function XmlHttpGET(xmlhttp, url) { 
    try { 
     xmlhttp.open("GET", url, true); 

     xmlhttp.send(null); 
    } catch (e) {} 
} 
+0

の異なるタイプを処理するためにCreateXmlHttpReq機能を微調整する必要があり、問題がxmlhttp.openであるように思われる(「GET」 、url、true);私は次に何をすべきかわからない – DaBears

答えて

0

ないように注意してくださいしかし、あなたは、私が言うことができるものとIE7では、MicrosoftのActiveXObjects

function CreateXmlHttpReq(handler) { 
    var xmlhttp = null; 

    if (window.XMLHttpRequest) { 
     xmlhttp = new XMLHttpRequest(); 
    } else if (window.ActiveXObject) { 
     var types = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Microsoft.XMLHTTP"]; 

     for (var i = 0; i < types.length; i++) { 
      try { 
       xmlhttp = new ActiveXObject(types[i]); 
       break; 
      } catch(e) {} 
     } 
    } 

    if (xmlhttp) { 
     xmlhttp.onreadystatechange = handler; 
    } 

    return xmlhttp; 
} 
+0

こんにちはSilentSakky-私はあなたのアプローチを試みましたが、私はIE7を実行しているマシンで成功のリターンを得られませんでした。思考? – DaBears