PDA

View Full Version : html5 web session storage



mutago
05-11-2014, 08:48 PM
i want to create a web storage session login and print a successful page (welcome.html) with the
loggin session username and password.

Login form works but those not display the welcome user on the successful page. any help

below is the code



$(document).ready(function(){
$("#rolling").slideDown('slow');
});
$(document).ready(function()
{
$("#submit").click(function()
{
if($("#uname").val()=="" || $("#pass").val()=="")
{
$("p").fadeTo('slow','0.99');
$("msg").hide();
$("p").fadeIn('slow',function(){$("p").html("<span id='error'>Please enter username and password</span>");});
return false;
}
else
{



$("p").html('<span class="normal"><img src="loading.gif"></span>');
var uname = $("#uname").val();
var pass = $("#pass").val();
$.getJSON("server.php",{username:uname,password:pass},function(json)
{
// Parse JSON data if json.response.error = 1 then login successfull
if(json.response.error == "1")
{


//store session
window.localStorage["uname"] = uname;
window.localStorage["pass"] = pass;
$.mobile.changePage("welcome.html");

}
// Login failed
else
{

data = "<span id='error'>Invalid account?</span>";
}




welcome.html



<!DOCTYPE HTML>
<html>
<head>
</head>

<body>

data = "<span id='msg'>Welcome "+uname+"</span>";

</body>
</html>

mutago
05-13-2014, 08:19 PM
Below is what am trying achieve, when a user login, on the successful page, it alerts eg welcome user, how will i print the welcome user on the body of the html as opposed to alerting it on the head



<!DOCTYPE HTML>
<html>
<head>

<script>
//sessionStorage.setItem('uname'); // defining the localStorage variable
alert("welcome: " + localStorage.getItem('uname')); // accessing it
confirm("welcome " + localStorage.uname); // another way of accessing the variable


</script>


</head>

<body>


welcome: " + localStorage.getItem('uname');

</body>

any help
</html>