前台调用接口出现两次请求解决办法

 前台调用接口出现两次请求解决办法

 这里用 vue-resource说明

this.$http.post('http://localhost/phpcrud/app.php?action=create',{
"username":this.customer.name,
"phone":this.customer.phone,
"email":this.customer.email
})

 

- 后台用的php

if ($action == "create") {
$input = file_get_contents("php://input");
$json = json_decode($input);
$username = $json->username;
$email = $json->email;
$phone = $json->phone;

$conn->query("set names utf8");
$result = $conn->query("insert into `users` (`username`,`email`,`phone`) values('$username','$email','$phone')");
if($result){
$res["message"] = "插入成功";
}else{
$res["message"] = "插入失败";
}
}

 在文件头部加上

 header('Access-Control-Max-Age: 3600');

猜你喜欢

转载自www.cnblogs.com/ayong6/p/12243021.html