我尝试使用 ajax 在 javascript 循环 (requestAnimFrame
) 中多次调用插入语句,但只有一个条目会输入到表中。
Ajax 调用 (mainpage.php
):
$.ajax({
type: "POST",
url: "ajaxPHP.php",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
},
error: function(err) {
// alert(err.toString());
if (err.status == 200) {
}
else { alert('Error:' + err.responseText + ' Status: ' + err.status); }
}
});
我的插入语句(inserts.php
):
$con = mysqli_connect("localhost", "root", "", "database");
$sql = "INSERT INTO testing values( '$x1', '$x2', '$x3','$x4', '$x5', '$x6', '$x7', '$x8', '$x9', '$x10', '$x11')";
mysqli_query($con, $sql);
mysqli_close($con);
注意:ajax block 在应该的时候运行(已达到),但插入语句不会插入新行,而是覆盖第一行的值。
任何帮助将不胜感激,谢谢!
最佳答案
我的程序中的错误不是代码本身,而是数据库结构。选择了不正确的主键
,导致新的插入语句覆盖以前的行。
关于javascript - 使用ajax创建迭代SQL `INSERT`语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25453686/