views:

596

answers:

3

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  A: 

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);
   }
});
Jimmy
+2  A: 

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
strager
Yep, though a 303 See Other is generally considered 'better'.
bobince
A: 

Thanks, I tried the redirect but I can't have the pages go back and forth like that, I need to learn AJAX...

Tommy
Why not? It basically causes a refresh of the browser, with a POST or GET in between.
strager
How does gmail delete all my files without going anywhere? ajax?
Tommy
OK, redirect is not so bad, thanks.
Tommy