When i call the function below:
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;
}
it will run - in that it will execute the php in savePlace.php (which runs a mysql update command). savePlace.php returns nothing currently, but it could return html or text if it's needed. In any case, the error handler is always executed. i have checked in the chrome js inspector, and it reports:
statusText:"error"
responseText:""
status:0
Here is the mysql code, if that helps
<?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";
?>
Note: I am running on localhost (my local machine, XAMPP)
I found the problem. I had to change the markup of a button that activated this function. For some reason that affected this.
I changed it from a to a . I'm not sure why that made a difference, but it appears to have fixed the problem.