相关疑难解决方法(0)

XmlHttpRequest错误:Access-Control-Allow-Origin不允许使用Origin null

我正在开发一个页面,通过jQuery的AJAX支持从Flickr和Panoramio中提取图像.

Flickr端工作正常,但当我尝试$.get(url, callback)从Panoramio时,我在Chrome的控制台中看到一个错误:

XMLHttpRequest无法加载http://www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&callback=processImages&minx=-30&miny=0&maxx=0&maxy=150.Access-Control-Allow-Origin不允许使用null.

如果我直接从浏览器查询该URL,它可以正常工作.发生了什么,我可以解决这个问题吗?我是不是错误地编写了我的查询,或者这是因为Panoramio会妨碍我正在尝试做的事情?

Google没有在错误消息上显示任何有用的匹配项.

编辑

以下是一些显示问题的示例代码:

$().ready(function () {
  var url = 'http://www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&callback=processImages&minx=-30&miny=0&maxx=0&maxy=150';

  $.get(url, function (jsonp) {
    var processImages = function (data) {
      alert('ok');
    };

    eval(jsonp);
  });
});
Run Code Online (Sandbox Code Playgroud)

您可以在线运行该示例.

编辑2

感谢Darin对此的帮助. 上面的代码错了. 请改用:

$().ready(function () {
  var url = 'http://www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&minx=-30&miny=0&maxx=0&maxy=150&callback=?';

  $.get(url, function (data) {
    // can use 'data' in here...
  });
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery jsonp xmlhttprequest cors

535
推荐指数
8
解决办法
74万
查看次数

如何通过javascript从html页面中的特定github txt文件中获取数据

我想获取这个网址的数据https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt#L2

我正在尝试使用 fetch api 来获取数据,但我收到了 cors 错误

这是我想要做的

async function showmodal1() {
    console.log("hello")
    const data = await 
                 fetch('https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt');
    console.log(data)
}
showmodal1();
Run Code Online (Sandbox Code Playgroud)

有什么方法可以获取 github txt 文件的数据我尝试通过互联网找到它,但我找不到任何东西提前谢谢您的帮助

编辑:

Access to fetch at 'https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. changelog.html:361 
GET https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt net::ERR_FAILED
showmodal1 @ changelog.html:361
(anonymous) @ changelog.html:365 …
Run Code Online (Sandbox Code Playgroud)

javascript fetch promise cors async-await

2
推荐指数
1
解决办法
1334
查看次数

标签 统计

cors ×2

javascript ×2

async-await ×1

fetch ×1

jquery ×1

jsonp ×1

promise ×1

xmlhttprequest ×1