2014-10-06 4 views
1

IE9에서 내 Haxe 게임을 표시하는 데 문제가 있습니다. 실제로 전혀 표시되지 않습니다. 우리는 컴파일 된 JS 파일 내에서 Haxe에 대한 문제를 추적하여 문제가 haxe.HTTP API에 있음을 확인했습니다.Haxe IE9 xmlHTTPrequest 문제

IE9가 xmlhttprequests와 작동하려면 확인하고 수행해야 할 몇 가지 사항이 있습니다. 이러한 일은 Haxe API에서 수행되지 않았습니다.

내 수정하지 않고 HTTP 클래스입니다 :

   this.url = url; 
       this.headers = new List(); 
       this.params = new List(); 
       this.async = true; 
      }; 
      $hxClasses["haxe.Http"] = haxe.Http; 
      haxe.Http.__name__ = ["haxe","Http"]; 
      haxe.Http.prototype = { 
       setParameter: function(param,value) { 
        this.params = Lambda.filter(this.params,function(p) { 
         return p.param != param; 
        }); 
        this.params.push({ param : param, value : value}); 
        return this; 
       } 
       ,request: function(post) { 
        var me = this; 
        me.responseData = null; 
        var r = this.req = js.Browser.createXMLHttpRequest(); 
        var onreadystatechange = function(_) { 
         if(r.readyState != 4) return; 
         var s; 
         try { 
          s = r.status; 
         } catch(e) { 
          s = null; 
         } 
         if(s == undefined) s = null; 
         if(s != null) me.onStatus(s); 
         if(s != null && s >= 200 && s < 400) { 
          me.req = null; 
          me.onData(me.responseData = r.responseText); 
         } else if(s == null) { 
          me.req = null; 
          me.onError("Failed to connect or resolve host"); 
         } else switch(s) { 
         case 12029: 
          me.req = null; 
          me.onError("Failed to connect to host"); 
          break; 
         case 12007: 
          me.req = null; 
          me.onError("Unknown host"); 
          break; 
         default: 
          me.req = null; 
          me.responseData = r.responseText; 
          me.onError("Http Error #" + r.status); 
         } 
        }; 
        if(this.async) r.onreadystatechange = onreadystatechange; 
        var uri = this.postData; 
        if(uri != null) post = true; else { 
         var $it0 = this.params.iterator(); 
         while($it0.hasNext()) { 
          var p = $it0.next(); 
          if(uri == null) uri = ""; else uri += "&"; 
          uri += encodeURIComponent(p.param) + "=" + encodeURIComponent(p.value); 
         } 
        } 
        try { 
         if(post) r.open("POST",this.url,this.async); else if(uri != null) { 
          var question = this.url.split("?").length <= 1; 
          r.open("GET",this.url + (question?"?":"&") + uri,this.async); 
          uri = null; 
         } else r.open("GET",this.url,this.async); 
        } catch(e1) { 
         me.req = null; 
         this.onError(e1.toString()); 
         return; 
        } 
        if(!Lambda.exists(this.headers,function(h) { 
         return h.header == "Content-Type"; 
        }) && post && this.postData == null) r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
        var $it1 = this.headers.iterator(); 
        while($it1.hasNext()) { 
         var h1 = $it1.next(); 
         r.setRequestHeader(h1.header,h1.value); 
        } 
        r.send(uri); 
        if(!this.async) onreadystatechange(null); 
       } 
       ,onData: function(data) { 
       } 
       ,onError: function(msg) { 
       } 
       ,onStatus: function(status) { 
       } 
       ,__class__: haxe.Http 
      }; 

이이 수정 프로그램 코드입니다 : 이것은 단지에 문 경우를 수행하지 않고 IE9 수정을 구현하는

  haxe.Http = function(url) { 
       this.url = url; 
       this.headers = new List(); 
       this.params = new List(); 
       this.async = true; 
      }; 
      $hxClasses["haxe.Http"] = haxe.Http; 
      haxe.Http.__name__ = ["haxe","Http"]; 
      haxe.Http.prototype = { 
       setParameter: function(param,value) { 
        this.params = Lambda.filter(this.params,function(p) { 
         return p.param != param; 
        }); 
        this.params.push({ param : param, value : value}); 
        return this; 
       } 
       ,request: function(post) { 
        var me = this; 
        me.responseData = null; 
        var r = this.req = js.Browser.createXMLHttpRequest(); 
        var onreadystatechange = function(_) { 
        console.log('in onreadystatechange function'); 
         //if(r.readyState != 4) return; 
         console.log(r.responseText); 
         console.log('r.status: ' + r.status); 
         me.req = null; 
         me.onData(me.responseData = r.responseText); 
        }; 
        if(typeof XDomainRequest != "undefined") { 
         console.log('XDomainRequest'); 
         r.onload = onreadystatechange; 
        } 
        var uri = this.postData; 

        try { 
         console.log('calling r.open with url: ' + this.url); 
         r.open("GET",this.url); 
        } catch(e1) { 
         me.req = null; 
         this.onError(e1.toString()); 
         return; 
        } 

          //r.send(uri); 
        //do it, wrapped in timeout to fix ie9 
        setTimeout(function() { 
          r.send(); 
         }, 0); 
        //if(!this.async) onreadystatechange(null); 

       } 
       ,onData: function(data) { 
       } 
       ,onError: function(msg) { 
       } 
       ,onStatus: function(status) { 
       } 
       ,__class__: haxe.Http 
      }; 

주 다른 브라우저를 계속 지원하십시오. 하지만 정말 쉽습니다. IF 문은 난 그냥 내가 Haxe 자체의 핵심 내에서 이러한 상황을 타개 할 수있는 방법 아무 생각이 없다, 문제가 무엇인지, 단순히 기본적으로

if(typeof XDomainRequest != "undefined") return new XDomainRequest(); 

입니다.

감사합니다.

답변