从离子2前端向php服务器发送HTTP请求

时间:2017-03-23 20:19:55

标签: angular ionic-framework ionic2

这是我在sign-up.ts

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

当我提交表单时,我在控制台中收到以下错误

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.

帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

您可以通过安装Chrome扩展程序SUM and AVERAGE functions

来尝试

工作原理:

Allow-Control-Allow-Origin: *

注意:您必须在使用其他网站时禁用此功能。

答案 1 :(得分:0)

将这些行放在signup.php脚本的顶部:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Credentials: true');