function submit(){ $.ajax({ type: "POST", url: "ajax.php", data: $('form').serialize(), success: function(msg) { $("#quiz_form,#demo1").addClass("hide"); $('#result').show(); $('#result').append(msg); } });
$response= $db->prepare("SELECT id,question_name,answer FROM questions"); $response->execute(); $i=1; $right_answer=0; $wrong_answer=0; $unanswered=0; while($result=$response->fetch(PDO::FETCH_ASSOC)) { // while($result=mysql_fetch_array($response)){ if($result['answer']==$_POST["$i"]){ $right_answer++; }else if($_POST["$i"]==5){ $unanswered++; } else{ $wrong_answer++; } $i++; } echo "<div id='answer'>"; echo " Right Answer : ". $right_answer."<br>"; echo " Wrong Answer : ". $wrong_answer."<br>"; echo " Unanswered Question : ". $unanswered."<br>"; echo "</div>";
submit
$("form").submit(function(e){ e.preventDefault(); $.ajax(... });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)