我使用Java Grizzly创建了一个本地HTTP服务器,其基本结构如下:
public static void main(String[] args) throws IOException {
Converter.register(); //local register
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.shutdown();
}
当我在本地浏览器上运行GET请求时,一切都很好:
但是当我尝试使用jQuery $ .get()(使用Brackets IDE Live Preview)时,它会失败:
function getRequest(){
var apiString = buildRequest();
$.get("http://localhost:8080/concord/webapi/from/dna/chr/10/strand/1/52500001..52567500/to/rna",function(r){
$('#outputPanel').text(r);
})
.fail(function(err){
// WHY THIS FAILS ?!?!
console.log(err);
});
}
我可以在控制台中看到我收到以下错误:
XMLHttpRequest cannot load http://localhost:8080/concord/webapi/from/dna/chr/10/strand/1/52500001..52567500/to/rna. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:61484' is therefore not allowed access.
当我呼叫远程响应(例如github api)时,它可以工作。 我正在寻找任何建议,谢谢。