XML 解析错误:找不到根元素位置 [英] XML Parsing Error: no root element found Location

查看:70
本文介绍了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 解析错误:找不到根元素位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆