问题
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