2013-09-05 1 views
6

주목할 가치 : 다음은 https를 통한 도메인 간 교차 작업입니다. 솔직히 IE10, Chrome 및 FF에서는 모든 것이 올바르게 작동하므로 문제가 아니라고 생각합니다. 내 생각 엔 IE8에서 XDomainRequest 개체 차이가있을 수 있습니까? 확실하지.Socket.IO 및 IE8 - jsonp- 폴링 연결이 항상 실패 함

아래의 sendLoginRequest 메서드는 먼저 호출되는 메서드입니다. 다른 모든 지원 코드도 아래에 나와 있습니다.

이것은 모두 매우 간단하지만 IE8이 실패한 이유는 확실하지 않습니다.

function WrappedSocket(data, session_string) { 
    var clientSocket = io.connect('https://xxxxxxxx/socketio', { query: "session=" +  encodeURIComponent(session_string), transports: ['jsonp-polling'] }); 
    clientSocket.socket.on("connect", function() { console.log("CONNECT_SUCCEED"); }); 
    clientSocket.socket.on("connect_failed", function() { console.log("CONNECT_FAILED"); }); 
    clientSocket.socket.on("reconnect_failed", function() { console.log("RECONNECT_FAILED"); }); 
    clientSocket.socket.on("error", function (eobj) { console.log("Socket error " + eobj); }); 
    console.log("Made a socket that is talking"); 
} 

var my_socket; 


function set_up_socket(data, sessionString) { 
    setSession(data.responseText); 
    my_socket = new WrappedSocket(data, sessionString); 
    my_socket.socket.emit("message", "Howdy!"); 
} 

function sendLoginRequest(loginCode, nextRequest) { 
    var xhr = createCORSRequest('POST', 'https://xxxxx/login', false); 
    var sessionString = 'xxxx'; 

    if ("withCredentials" in xhr) { 
     xhr.addEventListener("load", function() { 
      set_up_socket(this, sessionString); 
     }, false); 
    } 
    else { 
     xhr.onload = function() { 
      set_up_socket(this, sessionString); 
     }; 
    } 

    xhr.send(); 
    } 

function createCORSRequest(method, url, onload) { 
    xhrObj = new XMLHttpRequest(); 
    if ("withCredentials" in xhrObj) { 
     // Check if the XMLHttpRequest object has a "withCredentials" property. 
     // "withCredentials" only exists on XMLHTTPRequest2 objects. 
     if (onload) { 
      xhrObj.addEventListener("load", onload, false); 
     } 
     xhrObj.open(method, url, true); 
     xhrObj.withCredentials = true; 
    } else if (typeof XDomainRequest != "undefined") { 
     // Otherwise, check if XDomainRequest. 
     // XDomainRequest only exists in IE, and is IE's way of making CORS requests. 

     xhrObj = new XDomainRequest(); 
     xhrObj.open(method, url); 
     if (onload) { 
      xhrObj.onload = onload; 
     } 
    } else { 
     // Otherwise, CORS is not supported by the browser. 
     xhrObj = null; 
    } 
    return xhrObj; 
    } 

오류는 둘 다 콘솔에보고하고 있고 피들러 폴링은 사실 발생에 있지만 같은 실패는 각 설문 조사에 발생하는 유지 :

LOG:CONNECT_FAILED 
'f.parentNode' is null or not an object 
'f.parentNode' is null or not an object 
LOG:CONNECT_FAILED 
'f.parentNode' is null or not an object 
'f.parentNode' is null or not an object 
LOG:CONNECT_FAILED 
'f.parentNode' is null or not an object 
'f.parentNode' is null or not an object 
LOG:CONNECT_FAILED 
'f.parentNode' is null or not an object 
'f.parentNode' is null or not an object 
LOG:CONNECT_FAILED 
'f.parentNode' is null or not an object 
'f.parentNode' is null or not an object 
LOG:CONNECT_FAILED 
'f.parentNode' is null or not an object 
'f.parentNode' is null or not an object 

를 ........ ....

(당신은 아이디어를 얻을이이 여론 조사로 반복해서 발생합니다.)

을 다시 각 요청 F를 볼 수 있습니다 순차적으로 처리하면서 서버에서 200 개의 응답을 모두 받지만 CONNECT_FAILED 및 socket.io.js 파일의 JS 오류가 모두 발생합니다.

마지막으로 콘솔 화면에 위에서 본 오류 ("f.parentNode가 null이거나 객체가 아닙니다")를 위반하는 클라이언트의 socket.io.js 파일 코드입니다. 나는 그 객체가 null이라는 것을 이해한다. 왜 그것이 null인지는 알지 못한다.

........ 

if (this.isXDomain() && !io.util.ua.hasCORS) { 
    var insertAt = document.getElementsByTagName('script')[0] 
    , script = document.createElement('script'); 

    script.src = url + '&jsonp=' + io.j.length; 
    insertAt.parentNode.insertBefore(script, insertAt); 

    io.j.push(function (data) { 
     complete(data); 
     script.parentNode.removeChild(script); // *** BREAKS HERE!! *** 
    }); 

......... 
+0

를이 내 문제의 시작이 잘린 것처럼 보입니다. 문제에 대한 좋은 설명이있었습니다. 본질적으로 내가 제공 한 코드는 jsonp-polling을 사용하여 간단한 socket.io 연결을 수행합니다. IE8에서는 위에서 설명한 모든 세부 작업을 수행하지 않습니다. 보고 주셔서 감사합니다. –

+0

IE 9에서도 사용해 보셨나요? 그렇다면 헤더, doctype, 모든 부분과 함께 body open 태그까지 HTML 코드로 답장하십시오. 실제 내용을 변경할 수 있습니다. 당신이 훌륭한 바이올린을 만들 수 있다면. – MarmiK

+0

IE8은'.addEventListener()'를 지원합니까? Opera가 실제 이벤트를 사용하지 않았거나 사용하지 않았 음을 알고 있습니다. 즉 .onload()' –

답변

1

this answer 당, 나는 (나중에 추가 된 것으로 나타나거나 가장 등) IE8은 XMLHttpRequest() 개체에 대한 .addEventListener() 방법 또는 XDomainRequest()을 지원 믿지 않는다. 다른 최신 브라우저에 동일한 구문을 유지하려면

xhr.onload=function() { 
     set_up_socket(this, sessionString); 
    }; 

, 당신이 조건에 싸서 채울 백업 수 :

if(typeof xhr.addEventListener === undefined) 
{ 
    xhr.onload=function() { 
     set_up_socket(this, sessionString); 
    }; 
} 

에 코드의 해당 부분을 다시 작성하십시오

문제가 해결 될지 모르지만 도움이 될 수 있습니다.

MDN은 "More recent browsers, including Firefox, also support listening to the XMLHttpRequest events via standard addEventListener APIs in addition to setting on* properties to a handler function."입니다. 다시 말하지만, IE8이 어떤 브라우저를 언제 지원 하는지를 말할 수는 없기 때문에 어떤 브라우저를 말하지 않기 때문에 확실하지 않습니다.

관련 문제