【发布时间】:2014-05-29 22:02:17
【问题描述】:
内容中没有出现任何内容。
jQuery(function($) {
$.getJSON('http://countdown.tfl.gov.uk/stopBoard/55191')
.success(function(response) {
var $content = $('#content')
.html(response.arrivals[0].destination);
});
});
DIV 部分:
<div id="content"></div>
【问题讨论】:
-
XMLHttpRequest cannot load http://countdown.tfl.gov.uk/stopBoard/55191. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.始终检查您的控制台是否有错误。 -
这里也回答了这个问题以及解释/示例:stackoverflow.com/a/19821851/3535297
-
基本上你不能访问你自己服务器之外的资源,这是 web 开发中的一个已知问题(虽然有一些解决方法)。
-
你必须使用 jsonp 或者做一个跨域请求。 Ofc 服务器必须支持其中之一。
-
我不知道如何使用 JS 检索和操作数据。有什么例子吗?
标签: javascript html json getjson