HTTP Post Request

Hy all, actually I am getting ’ post ’ of undefined error. see below:
Screenshot_17
And here is my code:


Please help.

In my project I solved in this way:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-home',
  templateUrl: './home.page.html'
})
export class HomePage implements OnInit {

  constructor(private http: HttpClient) { 

    let data = JSON.stringify({
      key: 'val',
      key2: ' otherVal'
    });

    this.http.post('http://www.myRoot.it/api/myApp.php', data).subscribe((response) => {
      console.log(response);
    });
  }


}

On the server the Access-Control-Allow-Origin header must be set

1 Like

Thanks for replying, I was solved it with another way!