这里用 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‘);
原文地址:https://www.cnblogs.com/ayong6/p/12243021.html
时间: 2024-10-09 03:28:35