作者:真理难辩_175 | 来源:互联网 | 2023-10-12 10:20
所以我正在制作一个简单的登录/注册Web应用程序,但我不断收到以下错误:
XML Parsing Error: no root element found Location: file:///C:/xampp/htdocs/EdgarSerna95_Lab/login.html Line Number 37, Column 3:
和
XML Parsing Error: no root element found Location: file:///C:/xampp/htdocs/EdgarSerna95_Lab/php/login.phpLine Number 37, Column 3:
这是我的login.php
header('Content-type: application/json');
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jammer";
// Create connection
$cOnn= new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
header('HTTP/1.1 500 Bad connection to Database');
die("The server is down, we couldn't establish the DB connection");
}
else {
$conn ->set_charset('utf8_general_ci');
$userName = $_POST['username'];
$userPassword = $_POST['userPassword'];
$sql = "SELECT username, firstName, lastName FROM users WHERE username = '$userName' AND password = '$userPassword'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$respOnse= array('firstName' => $row['firstNameName'], 'lastName' => $row['lastName']);
}
echo json_encode($response);
}
else {
header('HTTP/1.1 406 User not found');
die("Wrong credentials provided!");
}
}
$conn->close();
?>
我已经做了一些关于xml解析错误的研究,但我仍然无法让我的项目工作,我试过谷歌Chrome和Firefox
解决方法:
AHA!今天得到了这个原因,这会让我看起来很傻,但有一天可能会帮助别人.
在我的机器上设置了Apache服务器,用PHP等等……我收到了这个错误…然后意识到原因:我点击了有问题的HTML文件(即包含Javascript / JQuery的文件),所以浏览器中的地址栏显示“file:/// D:/apps/Apache24/htdocs/experiments/forms/index.html”.
实际使用Apache服务器(假设它正在运行等)所要做的就是在浏览器的地址栏中输入“http://localhost/experiments/forms/index.html”.
在缓解方面,我到目前为止一直在使用“index.php”文件,只是改为“index.html”文件.有点困难,因为对于前者,你必须使用localhost“正确”访问它.