我的项目在后端使用spring,在前端使用angular2。我在spring项目的webapp文件夹下有一个json文件。我试图从角度访问它。Angular 2 - 没有访问控制允许源标题
我能够访问该文件,如果我只需键入“http://localhost:8080/project1/test.json”
但是如果我使用的角度相同的链接,我得到一个错误信息说“没有访问控制允许起源头”
我的角代码: 1.功能的getJSON()中定义的service.ts:
getJson(){
return this.http.get('http://localhost:8080/project1/test.json')
.map((response:Response) => response.json());
}
调用的getJSON():
results = []; (resJsonData => this.results = resJsonData);这是一个简单的方法。
我创建proxy.conf.json并添加以下行:
{
"/project1": {
"target": "http://localhost:8080",
"secure": false
}
}
而且还增加了“开始”: “NG服务--proxy-配置proxy.conf.json” to package.json
我仍然遇到同样的问题。我做错了什么?
什么是您的网址看看,当你调用这个页面是怎样的? – Chester
@Chester我可否知道你问了哪个网址? –
使用jsonp进行调用,如以下链接中所述:https://stackoverflow.com/questions/36289495/how-to-make-a-simple-jsonp-asynchronous-request-in-angular-2/36289568#36289568 – soulzcore