简体   繁体   English

从ionic 2前端到php服务器的HTTP发布请求

[英]HTTP post request to a php server from ionic 2 front end

This is my code in sign-up.ts 这是我在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. 帮助我解决这个问题。

You can try it by installing chrome extension Allow-Control-Allow-Origin: * 您可以通过安装Chrome扩展程序Allow-Control-Allow-Origin进行尝试:*

How it works: 这个怎么运作:

在此处输入图片说明

Note: You have to disable this when you use other sites. 注意:使用其他站点时,必须禁用此功能。

Put these lines into the top of your signup.php script: 将这些行放入signup.php脚本的顶部:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM