I have a login page and i want to store user information. If user is null, send user to login page, else user will continue to use application.
$.mobile.changePage("index.html");
My code is:
var obj; //user information (json)
$(document).ready(function(e) {
$("#btnlogin").click(function(){
var username=$("#lusername").val();
var password=$("#lpassword").val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Service1.asmx/Giris",
data: "{'kullaniciadi':'"+ username+"' , 'sifre': '"+password+"'}",
dataType: "json",
success: function(msg) {
obj = jQuery.parseJSON( msg.d);
if(obj!=null)
{
$.mobile.changePage("index.html");
}
else alert("not found");
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
});
});
Because i'm using $.mobile.changePage("index.html"); i can use the same java script at every page, i use alert and i works
$('#illnessDetailsPage').live('pageshow', function(event) {
alert(user);
});
My problem starts here, i use var obj//user info at the top of javascript but when page is change, it returns null.
Why it is null? (to learn javascript better) and how to solve problem?
Then how to control 'back' button to not load login page while logined? I didnt find any example, Thank You in advance. (I dont want to use localStorage)