跨域得到CSV文件 [英] Cross-Domain get CSV file

查看:318
本文介绍了跨域得到CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到一个CSV文件的股票从雅虎财经为成功 - 完全负载。我已经测试了不同的回调和其他问题的建议,但他们都不是工作 - 他们大多不输出任何东西。

I can't seem to get a CSV stock file from yahoo finance to "success"-fully load. I've tested different callbacks and suggestions from other questions, but none of them seem to be working - most of them don't output anything.

$(document).ready(function(){
    $.ajax({
        url:"http://finance.yahoo.com/d/quotes.csv?s=XOM&f=sn",
        dataType: 'jsonp',
        success: function(data) {
            alert('good');
        },
        error: function(data) {
            alert(data);
        }
    });
});

这code警报 [对象的对象] (错误回调),​​但是CSV文件可以在网络小组成功地看出。在网络面板中的数据读取(XOM)埃克森美孚CORPO预期(所以它没有负载)。

​This code alerts [object Object] (the "error" callback), however the CSV file can be seen in the network panel successfully. The data in the network panel reads "XOM, Exxon Mobile Corpo" as expected (so it did load).

我想真正的问题是我怎么能获得这些数据,我知道的是加载。我只是想警告现在它......只是想看看它在页面上。我花了几个小时与该摆弄了不知多少,这是行不通的。

I guess the real question is how can I get that data which I know is loaded. I just want to alert it for now... just want to see it on the page. I've spent a countless number of hours fiddling with this and it just doesn't work.

下面是一个的jsfiddle: http://jsfiddle.net/V94sQ/3/

Here's a jsfiddle: http://jsfiddle.net/V94sQ/3/

推荐答案

您不能请求从另一个域,除非他们支持CORS的CSV文件。既然你不控制雅虎你的运气那里。您将需要使用代理[从你自己的服务器请求它,后端使get请求]或<一href="http://www.yqlblog.net/blog/2009/06/02/getting-stock-information-with-yql-and-open-data-tables/"相对=nofollow>服务,可以使之成为一个JSONP请求。

You can not request CSV files from another domain unless they support CORS. Since you do not control yahoo you are out of luck there. You would need to use a proxy [request it from your own server, backend makes the get request] or a service that can make it into a jsonp request.

这篇关于跨域得到CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆