2 回答
TA贡献1846条经验 获得超7个赞
我认为您需要尝试更改代码
fetch('http://localhost:65535/login.php'....到您的 ip,使用ipconfig检查您的本地 ip 并像这样更改代码
fetch('http://192.168.1.1/login.php'....示例 ip
TA贡献2036条经验 获得超8个赞
据我所知,问题是您的 PHP 服务器没有返回有效的 json。它返回一个字符串,即使您对字符串进行 json_encode,该字符串也将是"Data Matched"或"Invalid Username or Password Please Try Again"。但是,当您发出 fetch 请求并执行
.then((response) => response.json())
.then((responseJson) => {
response.json()).then((responseJson)当您执行.json() 部分尝试解析无效 JSON 的字符串时,它会尝试解析字符串“数据匹配” 。因此,您可以通过两种方式解决这个问题,实际上从 php 服务器发回有效的 json 构建这样的对象{ "success" : true, message :"Data Matched"}或简单地删除 .json() 链,因此 javascript 将返回一个字符串,而不是尝试将其解析为 JSON。所以没有 .json() 它将是
...
.then((response) => {
// If server response message same as Data Matched
if(response === 'Data Matched')
{
alert(response);
} else {
alert(response);
}
...
只需先尝试删除.then((response) => response.json()第 58 行的部分,然后直接跳到下一个链接的 then 子句
添加回答
举报
