Issue seems to be that it's firing the error handler, never the success..
$('#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.');
}
});
});
Server-side being called via 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.'));
}
Many thanks..................................
console.log()instead ofalert()so that you can more easily copy and paste the error into your question. (Note that you don't need to useJSON.parse()within yoursuccesshandler, jQuery will parse it for you before calling the function because you specifieddataType: 'json'. This isn't causing your current problem, but once you solve the current problem it would be your next problem.)data: 'updatePlace=' + JSON.stringify(data)is incorrect since you do a post type not get you should try this insteaddata: {updatePlace: JSON.stringify(data)}errorThrownis blank, but for future reference don't do a+string concatenation ofXMLHttpReqest- log each argument separately.