【发布时间】:2026-01-16 00:00:02
【问题描述】:
我正在使用 REST API(特别是 this Hacker News API),并使用 jQuery 的 .get 方法来检索数据。到目前为止,这是我唯一的代码:
$.get( 'http://hnify.herokuapp.com/get/top', function(data) {
'use strict';
console.log(data)
});
这是我面临的错误:
XMLHttpRequest cannot load http://hnify.herokuapp.com/get/top. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
我在 Mac 上使用最新的 Google Chrome。我目前正在通过 localhost 查看它。
我对 REST API 非常非常陌生。提前致谢。
【问题讨论】:
标签: jquery rest get xmlhttprequest