2017-03-23 59 views
1

私は時間エラーを実行してしまった:が「XMLHttpRequestを」オン「オープン」の実行に失敗しました:無効なURL

Failed to execute 'open' on 'XMLHttpRequest': Invalid URL 
Error: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL 
    at http://localhost:8100/build/polyfills.js:3:2793 
    at XMLHttpRequest.open (eval at s (http://localhost:8100/build/polyfills.js:2:29793), <anonymous>:3:31) 
import { Injectable } from '@angular/core'; 
import { Http, Headers } from '@angular/http'; 
import 'rxjs/add/operator/map'; 

@Injectable() 
export class Reviews { 


    data: any; 

    constructor(public http: Http) { 
    this.data = null; 
    } 

    getReviews(){ 

    if (this.data) { 
     return Promise.resolve(this.data); 
    } 

    return new Promise(resolve => { 

     this.http.get('http://localhost:app/api/reviews') 
     .map(res => res.json()) 
     .subscribe(data => { 
      this.data = data; 
      resolve(this.data); 
     }); 
    }); 

    } 

    createReview(review){ 

    let headers = new Headers(); 
    headers.append('Content-Type', 'application/json'); 

    this.http.post('http://localhost:app/api/reviews', JSON.stringify(review), {headers: headers}) 
     .subscribe(res => { 
     console.log(res.json()); 
     }); 

    } 

    deleteReview(id){ 

    this.http.delete('http://localhost:app/api/reviews/' + id).subscribe((res) => { 
     console.log(res.json()); 
    });  

    } 

} 

答えて

8
http://localhost:app/api/reviews 

これは無効なURLです(エラーメッセージが言うだけのように)。

ホスト名の後に:がある場合は、そのあとにポート番号NUMBER(およびパス)を続けなければなりません。 appは数字ではなく、3文字です。

+0

ご利用いただきありがとうございました。 –

関連する問題