Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn a variable from Php to JQuery Ajax
    primarykey
    data
    text
    <p><strong>What I'm Trying to Do</strong><br /> 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.</p> <p><strong>What's Actually Happening</strong><br /> 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.</p> <pre><code>$("#leaderboardForm &gt; 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."); } }); }); </code></pre> <p><br /></p> <pre><code> $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 . "&lt;div style='width: 433px; padding: 8px; overflow: hidden; border: 1px solid #300; margin-bottom: 5px;'&gt;"; $leaderboard = $leaderboard . "&lt;div style='width: 200px; height: 30px; float: left;'&gt;"; $leaderboard = $leaderboard . "&lt;span style='color: #EFEFEF; font-weight: bold; font-size: 20px;'&gt;" . $row['leaderboard_name'] . "&lt;/span&gt;&lt;/div&gt;"; $leaderboard = $leaderboard . "&lt;div style='width: 200px; height: 30px; float: left;'&gt;"; $leaderboard = $leaderboard . "&lt;span style='color: #A00; font-weight: bold; font-size: 20px;'&gt;" . $row['leaderboard_score'] . "&lt;/span&gt;&lt;/div&gt;"; $leaderboard = $leaderboard . "&lt;/div&gt;"; } echo $leaderboard; mysql_close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload