I have in my java classes static variables CONSTANT_1, CONSTANT_2...
What is the best way to share these constants with my javascript functions or if there is a JQuery plugin for this.
Till now the only solution I can think of, is an ajax call in the beginning, to send these static variables to the client.
Thanks
I dont know whether this the best way or not, but it works.
var constant1=<%=class.CONSTANT_1%>;
you can set this static variable in a hidden field, then you can access it by javascript using this hidden field
<input type="hidden" value="<your static variable>" id="staticVariable" />
<script type="text/javascript">
function getStaticField(){
return document.getElementById("staticVariable").value;
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With