Home  >  Article  >  Web Front-end  >  How to use jquerysession

How to use jquerysession

WBOY
WBOYOriginal
2022-06-07 11:24:092703browse

In jquery, jquerysession is used to add, delete or obtain session data. It is a plug-in for operating sessions. It is also a library based on jquery for processing sessions. You can use "$.session.set('key' , 'value')" to add data, and "$.session.remove('key')" to delete data.

How to use jquerysession

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to use jquerysession

jQuery plug-in to operate session jQuerysession

Use sessionStorage object, which is similar to localStorage object, except that sessionStorage is used to store session data. This data will be cleared when the user closes the browser.

JquerySession is a library based on jquery for handling sessions. Using it can simplify our work. You need to introduce jquery before using it.

Add data

    $.session.set('key', 'value')

Delete data

    $.session.remove('key')

Get data

    $.session.get('key');

Clear data

    $.session.clear();

The example is as follows:

There is a requirement at work:

How to use jquerysession

#The table displays too many columns, and it is necessary to provide a function that can configure the display of hidden columns.

Initially, I want to save the displayed columns to the database. Later, a colleague provided an idea:

Hide all columns. When the page is initialized and loaded, the fixed-set columns are loaded by default. Then all columns are obtained on the front end, and a dialog box pops up to provide a check to save the data. Go to the JS session, then reload the parent page, load the columns configured in the session, and then load it.

$.session.set("key",value); 
$.session.get("key")

Need to import the jquerySession.js file.

Advantages of the method: convenient and concise, no need to exchange data in the background and front desk.

Disadvantages: Since the session of jquery is used, after the session expires, only the display columns with default settings can be loaded.

Video tutorial recommendation: jQuery video tutorial

The above is the detailed content of How to use jquerysession. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn