I have an executable on my web server that outputs XML to a file or standard output. The XML contains data I would like to turn into a table. This XML will be unique per user and will change on a periodic basis.
On my web page, I would like to:
-
Trigger running this executable on a set period (e.g. 30 minutes) to refresh the XML data
-
Parse this XML and dynamically add/remove table rows as the XML data changes between triggered runs
For #2, I think I can use $.ajax() to grab the server-side XML file and work with its contents, using innerHTML to render a table and add it to the web page.
I think the part I am stuck on is item #1. My web page is output from a Perl CGI script. Once the script is finished, the HTTP request is complete and there is no more communication between client and server.
Do I need to have a separate process running on the server that puts an XML file somewhere where the jQuery Ajax call can find it as needed? (I’d like to avoid this, as I’d have to manage many separate processes and XML files, depending on where the users are on the web site, whether they are logged in, etc.)
Or is there a cleaner way to have the client-side web page ask the web server to run a server-side executable, without reloading the web page? Something like a hidden form that, when triggered, can call an action without reloading the entire page?
Sorry if these are dumb questions. Thanks for your advice.
You can use jquery to execute a function every so often (say 30 mins) and make an ajax request to the server. In turn, the server will execute and request the XML file and push it to the javascript function where you can parse it.
The way I understand your question, #1 is not an issue. Once the web page is rendered there is nothing that you would have to do.
like this:
This is an asynchronous call to your server. then
somepageorformwill execute the cgi and generate the XML file. in the doSomething() function you would have the function that processes the XML as it will not execute until the process is done. I would assume the CGI would return the path to the file, so then in your function you would be able to get it and process it.