将服务器端值提升到客户端

I want to create a timer for a specific page. The value which should be put into the timer is inside a table. Lets suppose I get the variable from the table using mysql calls and put it inside a php variable.

What have I thought

Using a hidden field, echoing the php variable inside the hidden field's value. Getting the value in javascript.

The problem

The javascript code for the timer is executed at the start, and the hidden field normaly is put under the body tag. I am thinking this should rise some problems because the element is not created when the javascript function may check at start.

Which would be the best way to get this variable inside my javascript code so I can initialize my timer properly.

Have the JavaScript AJAX request the current state of the timer when it starts, and have PHP generate it on a different page.

By separating the two, you get more flexibility and power. Don't abuse hidden inputs for that.