问题似乎是它正在触发错误处理程序,而不是成功..
$('#editPlaceForm').submit(function() {
var placeName = $('#placeName').val();
$.ajax({
type: 'POST',
url: '../FormHandlers/myPlaces.php',
dataType: 'json',
data: {update_Place:true, place_Id : placeId, place_Name : placeName },
success:function(json) {
var result = JSON.parse(json);
if (result.success) {
$('#editPlaceModal').modal('hide');
if (locationsTable) {
locationsTable.fnDraw();
}
}
}, error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Sorry, an error occurred: Thrown: ' + errorThrown + ', Request: ' + XMLHttpRequest.getAllResponseHeaders().toString() +
', TextStatus: ' + textStatus + ', Please try again.');
}
});
});
通过 ajax 调用服务器端:
if (isset($_POST['update_Place'])) {
$place_id = htmlspecialchars($_POST['place_Id']);
$place_name = htmlspecialchars($_POST['place_Name']);
$update = "UPDATE locations SET name='" . $place_name . "' WHERE id =" . $place_id . ";";
$db->query($update);
$db->commit();
$db->close();
echo json_encode(array('success'=>'Changes were saved.'));
}
非常感谢..................................