简体   繁体   中英

Creating HTML page from Perl incl. Javascript: Refresh of Javascript variable

I am currently coding my intranet site, running on a Synology NAS. Since the intranet page (via Javascript) cannot access any folder on the NAS outside it's "www" folder, I had to this on the server side with a Perl script, since the data which should be displayed lies outside the "www" folder on the NAS.

The perl script now writes the entire html page, including Javascript code which is needed to plot a chart via dygraphs. The most important thing the perl script does is process a .csv file and write

var $chartdata = [["2014/07/06 12:05", 15], ["2014/07/06 12:06"], 15.5, ...];

which is the series variable as the dygraphs library (dygraphs.com) needs it to display the chart. Therefore I am dynamically writing a javascript line within the "script" tag. With the perl variables passed in the URL (script.pl?day=07&month=06&year=2014) this variable is written differently.

This all displays on an iPad and works fine.

I now have implemented the swipe function and would like to refresh the chart with data the day before or after the displayed date, depening on swiping left or right. The swipe function also works.

My problem is, how do I refresh/rewrite the javascript variable without needing to refresh the entire page? It works just executing the entire perl script with new data in URL variables, which in turn rewrites the entire html page. But I'd just like to refresh the chart, ie the data for the chart.

Any ideas on how to accomplish this?

Many thanks and best regards, dmy

You need to use AJAX . Probably the easiest way to do what you want is to set up an endpoint on your server that runs the perl script and spits out JSON that your graphing function can understand. When the page loads, make a request that gives you the default graph; when a user swipes, make a new request that gives you the graph appropriate for that, etc.

If you're using jquery, you can use this function .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM