I was just wondering what the best method / practices are for getting variables to a jQuery script.
I understand that you can add it as a
data-attribute, as I am currently doing. This works perfectly for small information required. But for example when I want to send an array of a thousand words to jQuery, I can imagine that it's far from perfect to add that as an
data-attribute in an HTML element.
Then I could do it within a
<script>-tag, and assign a variable there. But as I understand, this is not recommended as you do not want any 'in-line' script tags? As 3.2 is not adhering to this already (right?), I could aswell do it but is it wise?
Alternatively, I can use a jQuery
.get()-request to get the information, so I do not clumb up the HTML file and follow the best practices.
But then what route should I use for the request? And is this better than the forementioned options, as might not 'clumb up' the source, but does add a request?
- Do I use a custom route from my extension and send a response from my controller?
- Do I simply point to a file in my extension:
<root>/ext/vendor/extname/file.phpand send a response from there?