【发布时间】:2019-10-11 11:52:35
【问题描述】:
(我搜索了很多,在 Stack Overflow 上找不到这个问题)。
现在我正致力于通过 AJAX JavaScript 将大量数据从 HTML 保存到数据库到 php。这是我的 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);
?>
我的错误在哪里?
【问题讨论】:
标签: javascript ajax