Angular 从ionic 2前端向php服务器发送HTTP post请求
这是我在Angular 从ionic 2前端向php服务器发送HTTP post请求,angular,ionic-framework,ionic2,Angular,Ionic Framework,Ionic2,这是我在注册中的代码。ts let link = "http://localhost/signup.php"; this.http.post(link, signupdata) .subscribe(data => { console.log("Success"); },error => { console.log("Error"); }); 当我提交表单时,我的控制台中出现以下错误 XMLHttpRequ
注册中的代码。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.
请帮助我解决此问题。您可以通过安装chrome extension来尝试 工作原理:
注意:当您使用其他网站时,必须禁用此功能。将这些行放在signup.php脚本的顶部:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Credentials: true');
很高兴能为您提供帮助。别忘了投票支持我的答案;-)