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:

  1. create cron job a) fetches data, , b) writes file formatted using json conventions accessible web server,
  2. 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:

  1. adding error checking
  2. structuring namespace don't have many top-level variables
  3. adding data values existing javascript, rather separate file
  4. etc.

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -