无法在'XMLHttpRequest'上执行'open':无效的URL

问题描述 投票:2回答:1

我得到了运行时错误:

无法在'XMLHttpRequest'上执行'open':无效的URL错误:无法在'XMLHttpRequest'上执行'open':http://localhost:8100/build/polyfills.js:3:2793的XMLHttpRequest.open上的无效URL(eval at s(http://localhost:8100/build/polyfills.js:2:29793),: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());
    });    

  }

}
angular ionic2 mean
1个回答
14
投票
http://localhost:app/api/reviews

这是一个无效的URL(就像错误消息所示)。

如果主机名后面有:,则必须后跟NUMBER端口(然后是路径)。 app不是数字,而是三个字母。

© www.soinside.com 2019 - 2024. All rights reserved.