我的代码运行良好,除了“用户名”,由于某种原因,通过 JSON 发送字符串不会发布到表,它什么也不发送。
任何人都可以看到问题是什么?
jQuery
lowestScoreId = 1;
userPoints = 50;
userName = "ted";
$.getJSON("functions/updateHighScores.php", {lowestScoreId: lowestScoreId, userPoints: userPoints, userName: userName}, function(data) {
$('#notes').text(data.userName); //for testing
});
php
lowestScoreId = json_decode($_GET['lowestScoreId']);
$userName = json_decode($_GET['userName']);
$userPoints = json_decode($_GET['userPoints']);
include 'config.php';
$currentTime = time();
mysql_query("UPDATE highScores
SET `name` = '$userName',
`score` = '$userPoints',
`date` = '$currentTime'
WHERE id='$lowestScoreId'");
echo json_encode(array("userName" => $userName)); // for testing