I'm trying to send some data to save.php in order to save it in db. The thing is: Ajax post i success and it's returning right data in a console but 'echo' in save.php is returning nothing.I don't know what's wrong with this code.
var $nick = $('span.nick').html();
var $scores = points;
var range = n2;
var $upgrades =
{
'numbers': range,
'pointsPerSec': pps,
'multip': multi
};
//Save to DB
$.ajax({
url: "save.php",
type: "POST",
data: {
userID: $nick,
userPoints: $scores,
userUpgrades: $upgrades
},
async: false,
cache: false,
success: function(){
alert('Data saved');
console.log(save);
getData();
},
error: function(){
alert('You fucked up mate :(');
}
});
function getData(){
$.ajax({
type: 'GET',
url: 'save.php',
async: false,
cache: false,
success: function(data){
data = $.parseJSON(data);
$.each(data, function(i, save){
console.log(save);
});
},
error: function(){
alert('Error Ajax');
}
});
}
Here's my save.php file
if(isset($_POST['userPoints']) && !empty($_POST['userPoints'])){
$post=$_POST["userPoints"] or $_REQUEST["userPoints"];
$dec_post=json_decode($post);
echo $dec_post;
}