php - Instead of using a hard coded values in JavaScript, is it possible to use a cron to do it? -
it's easiest understand looking @ fiddle:
http://jsfiddle.net/tdbdw/1/ - apologies lack of css.
as can see, dynamically generated dropdowns , textboxes have big list of hardcoded values. have liked have pulled these straight database queries take long run them used in real-time - i.e. when user clicks on drop-down or tries type in auto-complete box.
instead have relevant queries run nightly using cron job question how take results of query , put them javascript file.
anyone have ideas how implement this?
any appreciated.
martin
the best route achieve want ("cron job creates data use javascript") go via json. involves:
- create cron job a) fetches data, , b) writes file formatted using json conventions accessible web server,
- amend html include file created cron job.
for simplicity create javascript file using contents similar following:
var agentvalues = [ "excel", "msword", "ppt", ]; you can create static first , last line, , add quoted values query in between. can load file html document other javascript:
<script type="text/javascript" src="..."></script> when populate autocomplete values, use for loop on array:
for (var = 0; < agentvalues.length; i++) { $("<option>" + agentvalues[i] + "</option>").appendto($values); } the above basic version of achieving aims, , can improve on it, e.g. by:
- adding error checking
- structuring namespace don't have many top-level variables
- adding data values existing javascript, rather separate file
- etc.
Comments
Post a Comment