(我搜索了很多,我在堆栈溢出上找不到这个问题(。
现在,我正在努力通过AJAX JavaScript到PHP保存大量数据从HTML到数据库。这是我的JavaScript代码:
function save()
{
var hist = document.getElementById("hist").value;
var mission = document.getElementById("mission").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200 )
{
UserAccountInfo = this.responseText;
alert(UserAccountInfo);
}
}
xmlhttp.open("POST","savecompany.php",true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("history="+hist+"&mission="mission);
}
代码在
上崩溃 xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
如果我评论了这一行,则使用计划字符串和数据库保存计划字符串!
提示我。这是我的php文件
<?php
require "conn.php";
$history= $_POST["history"];
$mission = $_POST["mission"];
$sql = " UPDATE company SET history ='$history' , mission='$mission' where id='1'";
mysqli_query($conn,$sql);
echo $history;
mysqli_close($conn);
?>
我的错误在哪里?
看起来您打算键入xmlhttp
并最终编写xhttp
。该变量未定义。