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對象 –