微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – XML解析错误:找不到根元素位置

所以我正在制作一个简单的登录/注册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

<?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“正确”访问它.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐