jQuery“getJSON”来自不支持JSON-P输出的外部域 [英] jQuery "getJSON" from an external domain that doesn't support JSON-P output

查看:120
本文介绍了jQuery“getJSON”来自不支持JSON-P输出的外部域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从外部网站上的JSON抓取数据,但该网站不支持JSON-P输出。这是一个非工作代码的例子,但是给了我想要实现的一个好主意:

  $。 getJSON(http://www.bom.gov.au/fwo/IDV60901/IDV60901.94868.json,function(data){
// Process data here
});

除了本地托管数据或使用AJAX / PHP下载和处理数据之外,还有其他方法呼叫?



提前感谢!

div class =h2_lin>解决方案

同源政策的大多数浏览器不会让你这样做没有一个愿意的外部服务器或服务器端代理。有几个黑客可以试试闪光灯:



http://flxhr.flensed.com/



这假设您的用户安装了Flash,但一般来说,如果他们安装了javascript,他们也有闪光灯...





如果您要查找的数据来自某个地方,它通过雅虎管道,他们将为您返回jsonp。



最好的运气!


I'm trying to grab data from a JSON on an external site but the site doesn't support JSON-P output. This is an example of non-working code, but gives a good idea of what I'm trying to achieve:

$.getJSON("http://www.bom.gov.au/fwo/IDV60901/IDV60901.94868.json", function(data){
    //Process data here
});

Are there ways around this other than locally hosting the data or downloading and processing it with an AJAX/PHP call? I would rather not have the server serve or download the data and rather have the user's browser grab it directly.

Thanks in advance!

解决方案

The Same Origin Policy of most browsers would not let you do this without a willing external server or a server-side proxy. There are a few hacks you could try out with flash:

http://flxhr.flensed.com/

This assumes your user has flash installed, but generally, if they have javascript installed, they also have flash...

OR

If the data you are looking for came as a feed somewhere, you could pass it through Yahoo Pipes and they will return jsonp for you.

Best of luck!

这篇关于jQuery“getJSON”来自不支持JSON-P输出的外部域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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