0
我想从一个特定的URL,它不工作的JSON对象由于某种原因。然而,相同的代码适用于不同的网址。在下面,如果我使用的代码“restcountries” URL它工作正常,并doesnt't工作“wingerweb ***”angularjs http.get网络服务调用不工作的特定url
import {Injectable} from "angular2/core"
import {Http} from 'angular2/http';
import 'rxjs/Rx';
import {Observable} from 'rxjs/Rx';
@Injectable()
export class CountryService{
//endpoint_url:String = "https://restcountries.eu/rest/v1/region/oceania";
endpoint_url:String = "http://cors.io/?u=http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1";
constructor(http: Http){
this.http = http;
}
getCountriesByRegion (region:String){
return this.http.get(this.endpoint_url)
.map(res => res.json())
.do(data => console.log(data))
.catch(this.handleError);
}
private handleError (error: Response) {
console.log('here');
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}
感谢您的响应。我做了并得到以下错误“SyntaxError:JSON.parse:意外的关键字在JSON数据的第1行第1列” –
我不认为'http://cors.io/?u = ...'是有效的URL。 – Win
我之前使用过相同的URL,并附有'cors'并且工作正常。由于某种原因,我无法直接使用'http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1'。这是一个有效的url并返回json对象 –