Pergunta

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

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top