从前端我js
将数据发送到后端php
:
async registerAsync(login: string, password: string): Promise<void> {
const resp = await fetch(`php-api/users/register?lg=${login}&ps=${password}`)
if (resp.status > 400) {
switch (resp.status) {
case 504: throw new Error("DB is offline")
default: throw new Error(resp.statusText)
}
}
localStorage.setItem("user", login)
}
在后端,我成功接受了参数(此外,我通过POST
请求尝试了它):
//// GET: api/register?lg=...&ps=...
public function RegisterAction() {
try {
$login = $this->requestParams["lg"];
$password = $this->requestParams["ps"];
$result = $this->repo->Register($login, $password);
return $this->response("OK");
} catch (Throwable $th) {
return $this->response($th->getMessage());
}
}
作为响应,php
控制器发送一个代码200
和一个消息。OK
我无法摆脱据称我的该网站密码已在 Google Chrome 中泄露的消息:此外,即使我在 Firefox 中完成此注册程序,然后尝试使用此数据进入 Chrome,该消息仍会出现。