I do something similar to this for my flashcard system.
I have a div for the "front" and the "back" of the current card, when the user gives their answer it loads the next card via the magic of ajax, json, and php.
Here is the relevant section of the answer page.
<h2>Answer:</h2>
<div class="qna">
<p id="question2" class="qna">SomethingsNotWorking.</p>
<p id="answer2" class="qna">SomethingsNotWorking.</p>
</div>
<h2>Did you know it?</h2>
<a >Submit</a>
<BR><a href="#" onClick="javascript:sendCardInfo('Yes')" name="knewIt">Yes</a>
<BR><a href="#" onClick="javascript:sendCardInfo('No')" name="knewIt">No</a>
This is the function that handles the users response by sending an ajax query.
function sendCardInfo(str){
//alert("sendCardInfo " + str);
$.ajax({
type: "POST",
url: "ajax.php",
data: "currentCard="+$(document).data('currentCard')+"¤tDeck="+$(document).data('currentDeck')+"&knewIt="+str,
dataType: "json",
success: function(data){
jQT.goTo('#home', 'swap');
// store the json response in the data object so it can be retrieved later.
$(document).data( "currentCard" , data.currentCard);
$(document).data( "currentDeck" , data.currentDeck);
$(document).data( "question" , data.question);
$(document).data( "answer" , data.answer);
// update the q and a divs with the current questions.
$('#question1').html( $(document).data( "question" ) );
$('#question2').html( $(document).data( "question" ) );
$('#answer2').html( $(document).data( "answer" ));
},
});
}
On the backend I have a PHP page called ajax.php generate the next card as JSON.