The code I am using is working ok but I am a bit stuck at trying to load a new page from a success function. The simplest way to put it is, how do I filter data coming from the php backend to make decisions? for example, I set a condition in the backend testajax.php page and in the ajax success function test for certain conditions. In php it would be something along the lines of using the if statement. I am quite new to jquery so would appreciate some guidance as to how to achieve this. Thanks
$.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
<?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';
}
?>
ajax part