JSFiddle - React, Tailwind, and code Playground
by rohanbhangui
HTML
<div id="stuff">
<?php
//points value is read from db here (outside of if statement)
if(isset($_GET['points']) && isset($_GET['answers'])) {
//sending stuff to db
//vaidate answer here in the php for security
//now for points once you update to db your done and you can go under the .done callback and just
//add 30 points to the total but for general example purposes lets do it in a more php way
echo (pointsFromDB+30)+"pts";
}
?>
</div>
JavaScript
$("#responder-button").on("click", function() {
var points = 30;
var answer = $("#pseudo-select").val();
//name the var going to php and the var that stores the value the same for ease
$.get( "index.php", { 'points': points, 'answer': answer} )
.done(function( data ) {
$("#stuff").html($(data).find("#stuff").html());
});
});