问题描述
我正在尝试从该网站获取Json格式数据.. http://www.livetraffic.sg /feeds/json
I am trying to get Json format data from this website .. http://www.livetraffic.sg/feeds/json
但是当我使用Ajax时..我在chrome控制台中遇到了这个特定错误.
however when i use ajax.. i run into this particular error in my chrome console.
错误:XMLHttpRequest无法加载. Access-Control-Allow-Origin不允许使用原点null.
Error:XMLHttpRequest cannot load. Origin null is not allowed by Access-Control-Allow-Origin.
外部网站是否阻止我使用信息?
Is the external website preventing my from using information?
感谢您的帮助!
我的代码示例:
url = "http://www.livetraffic.sg/home2/get_erp_gantry";
$().ready(function(){
$.get(resturl, function(data) {
//do something here with data
});
});
推荐答案
这是您的浏览器执行的同源策略.除了从中获取脚本的域之外,您不能向其他域发出请求.
This is your browser enforcing the same-origin policy. You are not allowed to make requests to domains other than the domain your script was fetched from.
您将必须在与提供脚本的域相同的域上设置一些服务器端代理,并提供数据. (如果可以的话,您也可以在服务器上缓存这些数据.)
You will have to set up some server-side proxy on the same domain as the one your script is served from and have it supply the data. (You could also cache this data on the server if it would make sense.)
这篇关于帮助从外部网站获取Json格式数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!