开发者

Jquery .post used to store php session variable. How to avoid refresh to call session value

I am using jquery's .post ajax call to pull an form input v开发者_如何学Pythonalue and pass it to a php file that starts a session and stores the value in it. The session value is then called on a different page.

The problem is, this all takes place without a page refresh, so the session value is always one page refresh behind. I.E. the first time the session value is called it is blank, but after refresh the value is loaded with the initial input value. When refreshing again, the session's second value is pulled. So, the session value is never current... it is one behind.

How can make it so the php session variable is current without needing to do a refresh?

Or, if this needs to be solved with a refresh, what is the best way to go about it?

Thanks for your help!


You can access the session id from the cookies assuming you are using the default setting for php sessions to use cookies. Javascript can access cookies.

However, do you really need the session id? The browser will send it for the next AJAX request you send so you shouldn't really need to do anything unless your doing something more complex with multiple session ids....


If you want to manipulate with this value just return it via jSON and do your logic in callback function.


I did not end up needing to use Sessions, or Cookies.

I found a solution to my problem here:

http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/

The issue was my input that the variable needed to be passed to was on a different page. Because I loaded this page with an iframe, I could carry the variable to the input with jQuery without the need for php sessions or php cookies. I used the technique that is in the linked post above.

Thanks to everyone who helped out.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜