当我调用下面的函数时:
function savePlace(id) {
var myName = $('#placeName').val();
var myAtmosphere = $('#placeAtmosphere').val()
var myType = $('#placeFoodType').val()
var myPrice = $('#placePrice').val();
$.ajax({
type: "POST",
url: "savePlace.php",
data: {"placeID" : id, "placeName": myName, "placeAtmosphere" : myAtmosphere, "placeType": myType, "placePrice" : myPrice},
dataType:"html",
success: function(data){
alert("YES");
},
// error function is always being called - even if database gets updated correctly
error: function (data) {
alert("no");
}
});
return false;
}
它将运行 - 因为它将执行 savePlace.php 中的 php(运行 mysql 更新命令)。savePlace.php 目前不返回任何内容,但如果需要,它可以返回 html 或文本。在任何情况下,错误处理程序总是被执行。我已经检查了 chrome js 检查器,它报告:
statusText:"error"
responseText:""
status:0
这是mysql代码,如果有帮助
<?php
require_once 'config/Common.php';
mysqli_report(MYSQLI_REPORT_ALL);
$placeID = htmlspecialchars(trim($_POST['placeID']));
$placeID = (int)$placeID;
$placeName = htmlspecialchars(trim($_POST['placeName']));
$placeAtmosphere = htmlspecialchars(trim($_POST['placeAtmosphere']));
$placeType = htmlspecialchars(trim($_POST['placeType']));
$placePrice = htmlspecialchars(trim($_POST['placePrice']));
$stmt = $EAE_CON->prepare("UPDATE EAE_PLACES SET NAME=?,ATMOSPHERE=?,FOOD_TYPE=?,PRICE=? WHERE idEAE_PLACES=?");
$stmt->bind_param('ssssi',$placeName, $placeAtmosphere, $placeType, $placePrice, $placeID);
$stmt->execute();
echo "Stuff";
?>
注意:我在 localhost(我的本地机器,XAMPP)上运行