我想在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";
}
*/
?>
问题来源于stack overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。