2016-10-10 10 views
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'); 
    } 
} 

答えて

0

では、以前に取得したURLをコードしてみてくださいもらえますか?例えば

、応答のための

endpoint_url:String = "http://cors.io/?u=" + 
    encodeURIComponent("http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1"); 
+0

感謝。 JSONデータ:JSON.parse:JSONデータの第1行第1列の予期しないキーワード " –

+0

" http://cors.io/?u = ... 'が有効ではないと思いますURL。 – Win

+0

私は前に同じURLを使用していましたが、 'cors'が追加されて正常に動作していました。何らかの理由で、「http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1」を直接使用することはできませんでした。これは有効なURLであり、jsonオブジェクトを返します –

関連する問題