0

This is my code in sign-up.ts

let link = "http://localhost/signup.php";
    this.http.post(link, signupdata)
      .subscribe(data => {
        console.log("Success");
      },error => {
        console.log("Error");
      });

when I submit the form I get the following error in my console

XMLHttpRequest cannot load http://localhost/signup.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

Help me in solving this.

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – AT82 Mar 23 '17 at 20:24

2 Answers2

0

You can try it by installing chrome extension Allow-Control-Allow-Origin: *

How it works:

enter image description here

Note: You have to disable this when you use other sites.

Sampath
  • 63,341
  • 64
  • 307
  • 441
0

Put these lines into the top of your signup.php script:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Credentials: true');
Chris
  • 4,672
  • 13
  • 52
  • 93