开发者

Using html hidden fields for storing temporary data

I'm plotting a graph using javascript flot library. When hovering or clicking i need to show more information. To do this, i'll need some more info. But flot will give me only the ( x, y ) co-ordinates of the clicked point.

Can I开发者_JS百科 store the info needed in html hidden fields ? Is it OK/Bad? Or should I use cookies? What about making extra ajax calls to fetch info ?

Thanks


You can do either JavaScript variables or hidden fields. The main benefit to using hidden fields would be if you end up submitting a form the data would already be in place.


I would use some Javascript in your page, given that (I assume) you'll have a Javascript event handler providing the information to the user. Something like:

<script type="text/JavaScript">
    data = [{x: 10, y:15, message:"This point is Foo"}, ... ];
</script>

I certainly wouldn't use cookies, and hidden fields, while they would work, would take more characters (more to transfer to the browser) and take more work for Javascript to extract the data from the DOM.

If you have so much data that your page size is too big (load time too long), then you would need to load the data via Ajax.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜