XML解析错误:找不到根元素位置 [英] XML Parsing Error: no root element found Location
问题描述
因此,我正在制作一个简单的登录/注册Web应用程序,但始终出现以下错误:
So I'm making a simple login/registration web application but I keep getting the following error:
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
here is my login.php
<?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解析错误的研究,但是我仍然无法使我的项目正常工作,尽管我曾在Google Chrome和Firefox上进行过尝试
I've done some research about xml parsing errors but I still cant manage to make my project work, ive tried with Google Chrome and Firefox
推荐答案
AHA!今天有这个原因,这会让我看起来很傻,但是有一天有可能 帮助某人.
AHA! Got this today for a reason which will make me look pretty silly but which might one day help someone.
已经在我的机器上使用PHP等安装了Apache服务器...我收到此错误...,然后意识到原因:我单击了相关的HTML文件(即包含Javascript/的HTML文件) JQuery),因此浏览器中的地址栏显示为"file:///D:/apps/Apache24/htdocs/experiments/forms/index.html".
Having set up an Apache server on my machine, with PHP and so on... I got this error... and then realised why: I had clicked on the HTML file in question (i.e. the one containing the Javascript/JQuery), so the address bar in the browser showed "file:///D:/apps/Apache24/htdocs/experiments/forms/index.html".
要真正使用Apache服务器(假设它正在运行等),必须要做的是".
What you have to do to actually use the Apache server (assuming it's running, etc.) is go "http://localhost/experiments/forms/index.html" in the browser's address bar.
为减轻风险,我到目前为止一直在使用"index.php"文件,而只是将其更改为"index.html"文件.有点麻烦,因为使用前者,您必须使用本地主机正确"访问它.
In mitigation I have up to now been using an "index.php" file and just changed to an "index.html" file. Bit of a gotcha, since with the former you are obliged to access it "properly" using localhost.
这篇关于XML解析错误:找不到根元素位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!