我们的登录代码有问题。我们不断收到 SyntaxError: JSON Parse Error:

我们缩小了在 .then(response) 行之一或 php 代码中发生的响应错误。我不确定我在这里做错了什么。有什么帮助吗?!
loginScreen.js
login = () =>{
const { UserEmail } = this.state ;
const { UserPassword } = this.state ;
fetch('http://localhost:65535/login.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
user_email: UserEmail,
user_pass: UserPassword
})
//Error within line 59-61 or php
})
.then((response) => response.json())
.then((responseJson) => {
// If server response message same as Data Matched
if(responseJson === 'Data Matched'){
alert("Correct");
} else{
alert("Incorrect");
}
}).catch((error) => {
console.error(error);
});
}
render() {
return (
<View style={styles.container}>
<ScrollView
style={styles.container}
contentContainerStyle={styles.contentContainer}>
<View style={styles.welcomeContainer}>
<Image
source={
__DEV__
? require('../assets/images/HootLogo.png')
: require('../assets/images/robot-prod.png')
}
style={styles.welcomeImage}
/>
</View>
login.php 似乎一切都正确布局并且可以正常工作。我尝试将 ' 更改为 ` 和所有内容。
<?php
// Importing DBConfig.php file.
include 'DBConfig.php';
// Creating connection.
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
// Getting the received JSON into $json variable.
$json = file_get_contents('php://input');
// decoding the received JSON and store into $obj variable.
$obj = json_decode($json,true);
// Populate User email from JSON $obj array and store into $email.
$user_email = $obj['user_email'];
// Populate Password from JSON $obj array and store into $password.
$user_pass = $obj['user_pass'];
慕姐8265434
喵喵时光机
慕桂英3389331
随时随地看视频慕课网APP
相关分类