Если ваша функция savechanges () возвращает значение, этот снимок кода отлично работает в моей системе.
$(document).ready(function(){
$('#saveRouteTrace').click(function(){
// Build latStr and lonStr
if(saveChanges()) {
$.post('stackoverflowajax.php', {
id: 9,
name:'Tsegay'
},
function(data) {
alert(data);
if(data.success) {
alert(data.reason);
}
else {
alert("Error: " + data.reason);
}
}, 'json');
}
});
function saveChanges(){
//This is a debuging code ... Make sure it return a value
return true;
}
});
Это файл на стороне сервера.Я повторяю файл JSON.
if(isset($_POST['id'])){
//This do not work
return '{ "success": true, "reason": "because it worked" }';
//this works fine
echo '{ "success": true, "reason": "because it worked" }';
}