【发布时间】:2013-12-27 17:58:25
【问题描述】:
我正在测试这个从 URL 检索天气数据的脚本。但由于某种原因,我没有得到回复。我启用了跨站点。有人可以指出问题吗?
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type:"GET",
url:"http://api.openweathermap.org/data/2.5/weather?q=London",
headers: { "Accept": "application/json; odata=verbose" },
crossDomain:true,
success:function(result){
$("#div1").html(result);
}});
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
【问题讨论】:
-
否,openweathermap.org 上未启用跨域来源
-
我怎样才能找到它?
-
chrome->inspect element->Network->Headers->Response-header.. 你看到一个字符串 Access-Control-Allow-Origin:*
-
更正 - 打开的天气图现在支持 CORS。
标签: javascript jquery ajax json