开发者

Run cgi script without changing the current html page?

I have a cgi script written in C, which is actually a client program. What I need to do is when the up arrow key is pressed, I need the cgi program to execute and send data to a C server program residing in my webserver?

How can I exectute cgi scripts without the page changing ? my C server program is listening on port 5000, my html page is i开发者_开发百科n http server at port 80. On loading, when the user presses the up arrow key, the cgi script must run and send a value 1 to the server program. Also my cgi script is a client program. I have already written the Javascript code to take keyboard inputs and displays particular values.


Running a CGI script is just a matter of making an HTTP request. There are numerous ways to do this without leaving the page.

Some of the more common ones are:

  • Load the URL in an (i)frame
  • Have the script return an image and dynamically generate an <img> element
  • Use XMLHttpRequest to make the request
  • Have the script return a piece of JS and dynamically generate an <script> element

Most of these come under the general heading of Ajax (and XHR being the most well associated method). There are plenty of libraries that help with this, and most big libraries (such as YUI and jQuery) include Ajax helper methods.


You want to communicate with the server without having to reload the page? Use AJAX (javascript framework).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜