2012-06-29 24 views
0

所以我的代码是调用我的服务器上的文件“zom3.ms3d”,我已经确认在那里,你也可以,以及所有的源代码。 (http://www.pso2u.com)XMLHttpRequest不断回来空

这是有问题的代码:

function getMs3dModel(model, name){ 
     var xhr = new XMLHttpRequest(); 
     xhr.open('GET', name, true); 
     xhr.responseType = 'arraybuffer'; 
     xhr.onload = function(e) { 
      parseBinFile(model, name, this.response); 
     }; 
     xhr.send(); 
    } 

而这正是它打印的内容(或前10个字节的话)

function parseBinFile(model, name, buffer){ 

     var headerStr = new DataView(buffer, 0, 10); 
     console.log(headerStr); 
    } 

为什么我的请求返回null?

+0

你使用什么浏览器?在Mac上运行Safari,响应是一个长度为99113字节的数组缓冲区。这听起来像你实际期待的。 – andypaxo

+0

使用firefox 15.0a2:< – CyanPrime

回答

0

尝试使用xhr.response,而不是this.reponse,通过this MDN article您使用的是什么浏览器

+0

这在Firefox中不起作用15.0a2 – CyanPrime

0

的建议? xhr.onload是XMLHttpRequest的2级以下的部分是浏览器的支持它的名单:http://caniuse.com/xhr2

您的代码看起来不错,但我会用xhr.response,不this.response(我一般避免“这'这些日子)​​。

+0

Aurora(Firefox)15.0a2(2012-06-28) – CyanPrime