XML Parsing Error: no root element found Location(XML 解析错误:找不到根元素位置)
问题描述
所以我正在制作一个简单的登录/注册网络应用程序,但我不断收到以下错误:
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! Got this today for a reason which will make me look pretty silly but which might one day help someone.
在我的机器上设置了一个 Apache 服务器,使用 PHP 等等......我收到这个错误......然后意识到原因:我点击了有问题的 HTML 文件(即包含 Javascript/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 服务器(假设它正在运行等),您需要做的是 "http://localhost/experiments/forms/index.html" 在浏览器的地址栏中.
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 解析错误:找不到根元素位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:XML 解析错误:找不到根元素位置
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01