我使用的代码工作正常,但我试图从成功函数加载新页面时有点卡住。最简单的方法是,如何过滤来自php后端的数据以作出决定?例如,我在后端testajax.php页面和ajax成功函数测试中为某些条件设置了一个条件。在PHP中,它将沿着使用if语句的方向发展。我对jquery很新,所以希望得到一些关于如何实现这一点的指导。由于从成功jQuery ajax加载页面
$.ajax({
type: "POST",
url: "testajax.php",
data: data,
success: function (data) {
$('#login_message').html(data);
//$(ok).val('Logged In');
//$("#login").get(0).reset();
//$("#form").dialog('close');
$.mobile.changePage("admin/index.php/", { transition: "slideup"});
},
error:function (xhr, ajaxOptions, thrownError){
alert('There was an exception thrown somewhere');
alert(xhr.status);
alert(thrownError);
}
});
testajax.php
// test wether the user session is already set
session_start();
$userpost = mysql_real_escape_string($_POST['user']);
if (!isset($_SESSION['user'])) {
$_SESSION['user'] = $userpost;
if($_SESSION['user']=='admin') {
echo 'Welcome Admin';
// for example, test data in ajax for
// this flag and if equal 1 then load admin/index.php
$flag = 'admin';
// end of flag
echo $flag;
}
else
echo 'Unknown User';
}
?>
2011-08-19
bollo