我想發送一些數據到save.php爲了保存在分貝。 問題是:Ajax發佈成功,它在控制檯中返回正確的數據,但save.php中的'echo'沒有返回任何內容。我不知道這段代碼有什麼問題。Ajax發送isaute
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');
}
});
}
這是我的save.php文件
if(isset($_POST['userPoints']) && !empty($_POST['userPoints'])){
$post=$_POST["userPoints"] or $_REQUEST["userPoints"];
$dec_post=json_decode($post);
echo $dec_post;
}
它返回0。 我該怎麼辦? – LastShadowPL
@LastShadowPL檢查你的PHP腳本,我不認爲它是使用正確的語法賦值$ post變量 –