0
特定のURLからjsonオブジェクトを取得しようとしていますが、何らかの理由で機能しません。しかし、同じコードは異なるURLでうまく動作します。以下のコード私は「restcountries」URLを使用する場合、それは正常に動作し、それがために働くdoesnt't「wingerweb ***」angularjs特定のURLに対してhttp.get Webサービス呼び出しが機能しない
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');
}
}
感謝。 JSONデータ:JSON.parse:JSONデータの第1行第1列の予期しないキーワード " –
" http://cors.io/?u = ... 'が有効ではないと思いますURL。 – Win
私は前に同じURLを使用していましたが、 'cors'が追加されて正常に動作していました。何らかの理由で、「http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1」を直接使用することはできませんでした。これは有効なURLであり、jsonオブジェクトを返します –