dongmaoxi0477
2010-01-18 04:27
浏览 47
已采纳

Jquery .post用于存储php会话变量。 如何避免刷新以调用会话值

I am using jquery's .post ajax call to pull an form input value 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!

图片转代码服务由CSDN问答提供 功能建议

我正在使用jquery的.post ajax调用来拉取表单输入值并将其传递给启动a的php文件 会话并将值存储在其中。 然后在不同的页面上调用会话值。

问题是,这一切都是在没有页面刷新的情况下发生的,因此会话值总是一页刷新。 I.E. 第一次调用会话值时,它是空白的,但刷新后,该值将加载初始输入值。 再次刷新时,将拉取会话的第二个值。 因此,会话值永远不会是最新的...它是落后的。

怎么能让php会话变量最新而不需要刷新?

或者,如果这需要用一个 刷新,最好的方法是什么?

感谢您的帮助!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongzun9958 2010-01-26 15:51
    已采纳

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dragon_9000 2010-01-18 04:43

    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....

    评论
    解决 无用
    打赏 举报
  • ds000001 2010-01-18 04:55

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题