Run CGI application without redirecting from HTML

梦想的初衷 提交于 2019-12-11 15:31:38

问题


I have an html page populated from a cgi app. Right now when I make a change on my html page through a form

<form action="/cgi-bin/Lib.exe" method=POST name="checks" ID="Form2">

It takes me from
http://localhost/index.html
to
http://localhost/cgi-bin/Lib.exe where the CGI outputs some debug lines I put in there. I then have to manually go back to the index to see it updated.

When the html form sends a request to the cgi application, the CGi application makes the update to the database and re-writes the index html. How do I stay on the index page and see it updated? (I am running the light weight GoAhead web server, CGI in C, and html,JS)

Thanks.


回答1:


You can send a 302 status code from the CGI script, which will redirect the user's browser to /index.html.

Basically, make the CGI script spit this out:

HTTP/1.1 302 Found
Location: /index.html

 



回答2:


you're basically asking "how do I use AJAX". I'd recommend using a library. In JQuery it would look something like:

$.ajax({
   type: "POST",
   url:  "/cgi-bin/Lib.exe",
   data: "foo=bar&spoo=fleem",
   success: function(html){
      $("#results").append(html);
   }
});


来源:https://stackoverflow.com/questions/448885/run-cgi-application-without-redirecting-from-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!