What I'm Trying to Do
I want to send a user's name and score to my php page where it inserts the data into the database, then spits out an html string showing the top ten scores.
What's Actually Happening
I enter the user's name and score and click submit. The data is sent over to php which then stores it in the database. The php file then constructs the string correctly which I can see by visiting the php page directly. However, the string is not returned back to my JQuery.
$("#leaderboardForm > input[type=image]").click(function() {
var theName = $("input#leaderboardName").val();
var theScore = $("input#theScore").val();
$.ajax({
type: "POST",
url: "../admin/submitleaderboard.php",
data: { leaderboardName: theName, theScore: theScore },
dataType: "html",
success: function(leaderboard) {
$("div#deadStats").html(leaderboard);
},
error: function() {
alert("An error occured submitting your score.");
}
});
});
$name = $_POST['leaderboardName'];
$score = $_POST['theScore'];
$sql="INSERT INTO leaderboard (leaderboard_date,leaderboard_name,leaderboard_score) VALUES (CURDATE(),'$name','$score')";
$result = mysql_query($sql);
$sql="SELECT * FROM leaderboard";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$leaderboard = $leaderboard . "<div style='width: 433px; padding: 8px; overflow: hidden; border: 1px solid #300; margin-bottom: 5px;'>";
$leaderboard = $leaderboard . "<div style='width: 200px; height: 30px; float: left;'>";
$leaderboard = $leaderboard . "<span style='color: #EFEFEF; font-weight: bold; font-size: 20px;'>" . $row['leaderboard_name'] . "</span></div>";
$leaderboard = $leaderboard . "<div style='width: 200px; height: 30px; float: left;'>";
$leaderboard = $leaderboard . "<span style='color: #A00; font-weight: bold; font-size: 20px;'>" . $row['leaderboard_score'] . "</span></div>";
$leaderboard = $leaderboard . "</div>";
}
echo $leaderboard;
mysql_close();
$.ajax,dataType: "json",means you're going to returnjsondata but your returned data doesn't seem likejson