开发者

Read Session value using JQuery

Is there any way to read Session value through JQuery?

Edited:

I am calling a .php file using JQuery. The .php file stores some column values in a session.

What would be the right approach to return those column values to the ca开发者_Python百科lling JQuery function?


In PHP, something like (from memory as I've not PHP'd for some time...)

<input type="hidden" id="SessionValue" value="<?php echo $MySessionValue ?>">

Then in jQuery

$("#SessionValue").val();


Sure you can set up a service which serves the Session values in JSON, and then use $.getJSON. But to read it directly is impossible.


Session values are stored on the server, JQuery is a client-side library that runs in the browser. Unless you send the session value down to the client, JQuery won't be able to read it.


I assume that you're referring to a server-side session in ASP.Net or PHP.

Not directly.

However, you could make an AJAX call to server-side code that returns something from the session.

If you do, beware of information disclosure.


Session values can only be read on server-side. Still if you are really hard-bent on what you want to do, you can write a Ajax enabled web-method in your code-behind that responds with session value for the given key as argument. You can call this webmethod from JQuery and retrieve the session value!


The ways sessions are associated with a client is by using cookies. That's where maybe the confusion takes place.

But the session data themselves are stored on the server.

Your backend need to send your session values somehow to your page for jQuery to pick it up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜