【问题标题】:Why does the server respond with Failed to load resource: the server responded with a status of 500 (Internal Server Error)? How can I solve it?为什么服务器响应加载资源失败:服务器响应状态为 500(内部服务器错误)?我该如何解决?
【发布时间】:2019-11-17 10:33:36
【问题描述】:

我想在 Ajax 中传递数据,但是在运行该函数时,当我检查元素时会出现内部服务器错误。我正在构建一个登录表单,但是当单击登录按钮时,它会出现内部服务器错误。

     function login (){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        console.log("Test2");
        document.getElementById("IdForm").innerHTMl = this.responseText;
        console.log("Test3");
        alert (this.responseText);
    }
};

xhttp.open("POST", "PHP/login.php", true);
var data = new FormData(document.getElementById("IdForm"))
console.log("Status500")
xhttp.send(data);

return false;
    }

我这里有 PHP 代码:

     <?php
      $servername = "localhost";
      $username = "*****";
      $password = "******";
      $dbname = "*******";
      //create connection
      $conn = new mysqli ($servername, $username, $password, $dbname);
     //Check connection

     if ($conn ->connect_error) 
     {
     die("connection failed:" . $conn -> connect_error);
      }
     $sql = "SELECT * FROM accounts";
     $result = $conn ->query($sql);
     $out = "";
     $rc = "";
     if ($result->num_rows > 0)
     {
    while($row = $result -> fetch_assoc())
     {

    echo "<p> " . $_POST ["username"] . "</p>";
    if (($row ["username"] == $_POST ["username"]) and $row ["password"] == $_POST ["password"])
    header('Location: ok.html');
    else
    echo "User not valid";
     }
     } else{
    echo "0 results";
     }
     */
      ?>

【问题讨论】:

标签: php sql ajax


【解决方案1】:

您似乎有一个结束评论标签*/ 没有评论开始。对于 PHP,这是一个语法错误/错字。如果您删除标签,它可能会起作用

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 1970-01-01
    • 2018-01-22
    • 2014-11-24
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多