我在Brackets上使用邮递员休息客户端。使用该客户端,我可以请求 Gogs api。但是,如果我想使用 jquery 请求它,我会得到:
XMLHttpRequest cannot load http://xxx.xxx.xxx.xxx:3000/api/v1/repos/.../.../issues?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
这是我的js代码:
var request = $.ajax({
url: apiUrl+'repos/.../.../issues?token='+token,
method: "GET",
dataType: "json",
crossDomain: true
});
request.done(function( data ) {
resolve('it works', data);
});
request.fail(function( jqXHR, textStatus ) {
reject(jqXHR, textStatus);
});
任何想法如何解决这个问题?
编辑: 目前它仅用于开发。因此我可以使用这个 Chrome 扩展:Allow-Control-Allow-Origin: *