0

我正在使用 jsonp 从 api 获取一些内容。

问题是我拥有的链接返回一个要保存为 CSV 的文件,响应是application/x-octet-stream.

如果我查看 chrome 开发人员工具,我会收到此错误Resource interpreted as Script but transferred with MIME type application/x-octet-stream:...,并且Uncaught SyntaxError: Unexpected identifier.

但是,如果我查看previewresponse选项卡,我可以看到我的数据。

有没有办法获取这些数据?

一种解决方案是让我在 php 中设置不同的标题,但我的整个页面都会中断

有任何想法吗?

谢谢

4

1 回答 1

0

尝试这个-

function main() {
    var xhr;

    xhr = new XMLHttpRequest();
    xhr.open("GET", "foo.csv?r=" + Math.random(), true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            //xhr.responseText stores your CSV Content
            document.querySelector("body").innerHTML = xhr.responseText;
        }
    };
    xhr.send(null);
}
于 2013-05-22T05:42:03.370 回答