简体   繁体   English

XMLHttpRequest不断返回null

[英]XMLHttpRequest keeps coming back null

So my code is calling for a file on my server "zom3.ms3d" which I have confirmed is there, and you can too, along with all the source code for this. 因此,我的代码正在我的服务器“ zom3.ms3d”上调用一个文件,该文件已经确认存在,您也可以将其与所有源代码一起使用。 (http://www.pso2u.com) (http://www.pso2u.com)

This is the code in question: 这是有问题的代码:

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();
    }

And this is where it prints the contents (or first 10 bytes of it) 这是打印内容(或内容的前10个字节)的地方

function parseBinFile(model, name, buffer){

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

Why is my request coming back null? 为什么我的请求返回为空?

尝试使用xhr.response而不是this.reponse ,如MDN文章所建议的那样

What browser are you using? 你使用的是什么浏览器? xhr.onload is part of XMLHttpRequest Level 2. Here is the list of browsers supporting it: http://caniuse.com/xhr2 xhr.onload是XMLHttpRequest Level 2的一部分。这是支持它的浏览器列表: http : //caniuse.com/xhr2

Your code looks good, though I would use xhr.response , not this.response (I generally avoid 'this' these days). 您的代码看起来不错,尽管我会使用xhr.response ,而不是this.response (这些天我通常避免使用“ this”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM