문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top