我正在使用Vue js开发Scrumpoker。
我有一个用于用户和会话的模型,这些模型存储在数据库中,具有诸如sessionID,nameID,userID等属性。
我正在尝试让用户加入不是由他创建的房间。
如果我尝试这样做,则会在查看Web开发人员面板时收到一条错误消息,提示:
POST http://127.0.0.1:8090/xdd/src/api/user/create.php 400 (Bad Request)
vue-resource.esm.js?f3ef:1082
当我加载包括create.php的本地路径URL时,它说:
通知:尝试在 C:\ laragon \ www \ xdd \ src \ api \ user \ create.php 中获取非对象的属性“ userName”第 19
行
通知:尝试在行上的 C:\ laragon \ www \ xdd \ src \ api \ user \ create.php 中获取非对象的属性“ sessionId” > 20
有人可以帮助我吗? (用纸牌)解决有关api的最大问题是最后一件事。
这是我的user / create.php代码:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
include_once '../config/db.php';
include_once '../models/user.php';
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$data = json_decode(file_get_contents("php://input"));
$user->userName = $data->userName;
$user->userSession = $data->sessionId;
if($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
echo "OPTIONS";
} else {
switch($user->create()){
case "NEW USER":
$insertId = $db->lastInsertId();
echo "$insertId";
break;
case "EXISTING USER":
echo "$user->userId";
break;
case "SESSION NOT FOUND":
http_response_code(404);
break;
default:
http_response_code(400);
}
}
?>
Request URL: http://127.0.0.1:8090/xdd/src/api/user/create.php
Request Method: POST
Status Code: 400 Bad Request
Remote Address: 127.0.0.1:8090
Referrer Policy: no-referrer-when-downgrade
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Connection: close
Content-Length: 95
Content-Type: application/json; charset=UTF-8
Date: Wed, 11 Sep 2019 13:53:47 GMT
Server: Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11
X-Powered-By: PHP/7.2.11
Provisional headers are shown
Accept: application/json, text/plain, */*
Content-Type: application/json;charset=UTF-8
Origin: http://localhost:8080
Referer: http://localhost:8080/join/32
Sec-Fetch-Mode: cors
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
{userName: "a", sessionId: "32"}
sessionId: "32"
userName: "a"