Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store user properties as a global variable in jQuery

Tags:

jquery

model

I can program with a number of client side technologies such as extjs, gxt and others but I am new to jQuery.

I am used to be able to store complex models on the client side and keep referring to it wo going back to the sever.

For example, after login, I want to be able to retain all user info, name, role, etc. Then later, upon clicking a button, the event handler can do different things depending on whether the user is admin or standard user.

How would you implement that in jQuery.

like image 849
bhomass Avatar asked Jan 19 '26 06:01

bhomass


1 Answers

It's important to note that the problem you are trying to solve was not what jQuery was meant to do or what it was designed for. jQuery is primarily about DOM manipulation (although it has extended some). However, there are a number of other libraries that work in conjunction with jQuery to do what you want to do - primarily KnockoutJS. From Knockout's website: "Easily associate DOM elements with model data using a concise, readable syntax"

In addition, if you just want to store data on the client side, I would recommend looking into localStorage and sessionStorage. Both of these aspects of web programming were designed for the specific problem you are facing. However, be careful with what data you store as this can become a point of data access.

like image 124
JasCav Avatar answered Jan 20 '26 22:01

JasCav