Reputation:
I have a web page with a switch (html & CSS) and a toggle function (JS) which changes the appearance of the switch as it is clicked. The toggle function has a 'standby' variable which tracks the status of the switch. I also have a form (JS) which POSTs the value of standby to a cgi script (python) which will control some lights. That all works! Except, I do not want the cgi file to respond with a new web page or even reload the current web page - I'd like to keep the page as it is - which does not seem possible with cgi! I'm guessing cgi is the wrong approach (& this is another dumb question!) Thanks in advance...
Upvotes: 0
Views: 429
Reputation:
Thanks for all the answers - I appreciate you putting me on the right track. I used JQuery and ajax as suggested and it is working - simple when you know how!
This is in index.html:
$.ajax({
type: "POST",
url: "/cgi-bin/standby.py",
data: {status: standby}
});
and in standby.py:
data = cgi.FieldStorage()
data = data["status"].value
Upvotes: 1
Reputation: 2811
You’ll need to make your request asynchronously using JavaScript.
Have a look at the XMLHttpRequest object or use a wrapper function like jQuery’s $.ajax method (especially if you want to support older browsers).
Please see this answer for an example of how to do a POST request using the XMLHttpRequest object.
Upvotes: 1
Reputation: 4552
You can send your Form using Ajax. The easiest way is to use Jquery.
Here is a nice tutorial: http://hayageek.com/jquery-ajax-form-submit/
Upvotes: 1