开发者

Messaging back from CGI

I programmed a CGI application written in C that downloads external data and inserts it into a MySQL database. This is done and works and I can call it directly from my CGI-BIN folder.

Now I want the user to be able to press a refresh button which in turn loads the CGI script and then shows a loading indicator. I was thinking of using Javascript to load a PHP script that then loads the CGI-APP. While CGI is at work the user should see a loading indicator.

How can I now let the main PHP know that it all worked out if I only call the script indirectly with XMLHttpRequest as I do?

mainapp.php > Javascript XMLHttpRequest > loader.php > CGI app

How does the info from CGI app that all worked get back to mainapp.php to reload itself?

EDIT: I forgot to mention. I use JS to make the transition smoothly so the user doesn't "feel" another pag开发者_开发问答e has just been loaded.


Server side, the CGI script could publish its progress as it runs. This could be written to a file, uniquely identified for this invocation. When the process is kicked off, the JavaScript would be told about this unique identifier.

(The file could simply contain 0-100 depending on progress.)

You could then poll for the contents of this file (i.e. http://site/services/status/uniqueid) at a given interval using an XHR and update your user interface accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜