前台調用接口出現兩次請求解決辦法


 前台調用接口出現兩次請求解決辦法

 這里用 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');


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM