0

Hi i am getting this strange problem. I am setting a cookie in external javascript file with current user time. I want this time to be available to the server so i am retrieving this using a php cookie.

I am able to fetch the value but only if i refresh the browser 2 times. If i change my current system time, and then refresh the page i still see old time,but when i refresh again then i see updated time.

I am doing something like this: enter code here

External js file

var now=new Date();
currTime=now.getHours();
document.cookie = "currentTime = " +currTime;

module file

$current_time = $_COOKIE["currentTime"];
echo $current_time;

I am calling the external js file in hook_nodeapi() using drupal_add_js

As I said, I am able to get the updated value of current time from cookie but only if I refresh 2 times.

What could be the problem?

thanks

4

1 回答 1

0

Download and use jquery.cookie.js from https://github.com/carhartl/jquery-cookie

Document for jquery.cookie is available at http://code.google.com/p/cookies/wiki/Documentation

于 2012-05-21T15:41:47.383 回答