2012-06-29 23 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