2つのテキストボックスと2つのボタン(1つは送信ボタン、1つはボタン)のフォームがあります。ボタンをクリックして呼び出すと、データ「CheckRegistration」を使用してajax呼び出しを行う必要があります。最後に、ViewRegisteredStudents()関数を呼び出します。「resultVal」攪拌がajax呼び出しに返されることを期待していますが、「resultVal」文字列とフォーム(2つのテキストボックス、2つのボタン)が返されます。
$(document).ready(function(){
$(':button').click(function(){
$.ajax({
Url:"SkiiTripDB.php",
type:"POST",
data:{call:'CheckRegistration'},
dataType:"html",
success:function(data){
$('div#registeredStudents').html(data);
}
});
});
});
if(isset($_POST['call']))
{
$call=$_POST['call'];
$connection=IsDatabaseConnected($strServer,$strUsername,$strPassword,$strDatabaseName);
switch($call)
{
case 'CheckRegistration':ViewRegisteredStudents();
break;
}
closeDatabaseConnection($connection);
}
function ViewRegisteredStudents()
{
$resultVal="";
$resultVal.="<table border='2'>";
$resultVal.="<tr>";
$resultVal.=" <th>Student Name</th>";
$resultVal.=" <th>Student Class</th>";
$resultVal.=" </tr>";
// Query database
$strSqlQuery="SELECT sSName, sClass FROM tripregistration";
$result=mysql_query($strSqlQuery);
while($row=mysql_fetch_array($result))
{
$resultVal.="<tr>";
$resultVal.="<td>".$row['sSName']."</td>";
$resultVal.="<td>".$row['sClass']."</td>";
$resultVal.="</tr>";
}
$resultVal.="</table>";
echo $resultVal;
}