Using "PHP" inside front end scripts |
(07-02-2015, 08:47 AM)kamenjan Wrote: Are you aware of any online resources describing this methodology? I tried searching for something like "using php cached variables in script", but was unsuccessful. The basic idea is to echo the $js_answers variable into the HTML in your view instead of your script, then use JavaScript to retrieve the value from the DOM and pass it into your script. In most cases, you can encapsulate most of your code into reusable .js files with objects/functions/methods, which you can read about almost anywhere (I prefer https://developer.mozilla.org, but in some areas they don't do much more than give you the specs). Then you can either: - determine a convention to follow within your Views' HTML to pass data to your script and create a common script you use to check for the presence of the data and call the appropriate methods in your JS; or - add a small script to individual Views as needed to retrieve the data and call the appropriate methods. For example, if you're using jQuery, you might do something like this: Code: <div id="surveyResultsDiv" data-answers="<?php echo $js_answers; ?>"> |
Messages In This Thread |
Using "PHP" inside front end scripts - by kamenjan - 07-02-2015, 06:48 AM
RE: Using "PHP" inside front end scripts - by BeYourCyber - 07-02-2015, 08:07 AM
RE: Using "PHP" inside front end scripts - by mwhitney - 07-02-2015, 08:16 AM
RE: Using "PHP" inside front end scripts - by kamenjan - 07-02-2015, 08:47 AM
RE: Using "PHP" inside front end scripts - by mwhitney - 07-02-2015, 11:18 AM
|