Ошибка: Uncaught (в обещании): Ответ со статусом: 0 для URL: нулевой статус: 404 - PullRequest
0 голосов
/ 23 января 2019

когда я пытаюсь нажать на URL-адрес пост-запроса, у меня появляется эта ошибка

Error: Uncaught (in promise): Response with status: 0  for URL: null
    at c (http://localhost:8100/build/polyfills.js:3:19752)
    at c (http://localhost:8100/build/polyfills.js:3:19461)
    at http://localhost:8100/build/polyfills.js:3:20233
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
    at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
    at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
    at o (http://localhost:8100/build/polyfills.js:3:7894)
    at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16823)
    at p (http://localhost:8100/build/polyfills.js:2:27648)

Мой код машинописного текста

public getCategory(){
        console.log('test');
        return new Promise((resolve, reject) => {
        let header = new Headers();
        header.append('Content-Type', 'application/x-www-form-urlencoded');
        let curr_page = { "currentPage":1,"pageSize":2 };
        // var page_size = 5;
        this.http.post(this.db,JSON.stringify(curr_page),{headers: header}).map(res=>res.json())
        .subscribe(res=>{
          console.log(res);
          resolve(res);
        }, (err) => {
          reject(err);
        });
    });
  }

, но когда я пытаюсь нажать на этот URL-адресПриложение почтальон работает, ждет помощи.

1 Ответ

0 голосов
/ 23 января 2019

вот подпись метода http post в угловом формате

post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;

Вы можете попробовать следующий способ

var options = new RequestOptions();
options.headers = new Headers();
options.headers.append( 'Content-Type', 'application/x-www-form-urlencoded');
let curr_page = { "currentPage":1,"pageSize":2 };
    // var page_size = 5;
    this.http.post(this.db,JSON.stringify(curr_page),options).map(res=>res.json())
    .subscribe(res=>{
      console.log(res);
      resolve(res);
    }, (err) => {
      reject(err);
    });
...