我有一个窗体有两个文本框和两个按钮(一个提交按钮,一个按钮)。当我打电话点击按钮,它必须使用数据“CheckRegistration”进行ajax调用。最后,它会调用ViewRegisteredStudents()函数。我期待“resultVal”stirng被返回到ajax调用,但它返回“resultVal”字符串和窗体(两个文本框,两个按钮)。jquery ajax返回数据不工作
$(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;
}
你为什么在同一个blockquote中粘贴'javascript'和'php'的代码?这是与我的大脑搞乱... – 2012-08-16 10:32:46
嗨,我很抱歉。现在,我分开 – dotnetrocks 2012-08-16 10:36:57