How-to store variable beetween jQM pages?

后端 未结 4 1470
忘掉有多难
忘掉有多难 2020-12-11 10:40

How do I pass a variable like username between two jQueryMobile pages?

or two regular pages for that matter, having the variable as global does not work, since at th

4条回答
  •  萌比男神i
    2020-12-11 11:04

    I usually go with local storage, you can store objects too. Ex:

    var userInfo = {
                "username": "Bob",
                "roleName": "Admin",
                "image": "img/userPic.jpg",
            };
    
            //Store the object in local storage
            localStorage.setItem('loggedUser', JSON.stringify(userInfo));
    

    then on the other page you can simply do:

    var userInfo = JSON.parse(localStorage.getItem("loggedUser"));
    var userName = userInfo.username;
    

提交回复
热议问题