Over the past few years, I have always used a hidden <input> field on the client side to store the value on the server side and use it on Javascript ground.
For example, let's say I need an Ajax timeout value from my application configuration.
I would probably save it in my JSP:
<input type="hidden" id="ajaxTimeout" value="${serverValue}" />
and then use it so that my AJAX call lives in an external file:
$("#ajaxTimeout").val()
Today I discussed this, and it has been suggested that it is better to store values that will be used only by Javascript in HTML <meta> tags.
Does it matter? Is there a preferred way to get server-side information that should only be used in Javascript?
I understand that if the hidden input field is not part of the form, then it is safe enough to store the value, since it will not be attached to any requests. Having said that, I always thought that it was really a cue ball.
Thoughts?
:: EDIT ::
Two fantastic answers:
javascript html client-side server-side hidden-field
wild_nothing
source share