I am using mod_python
publisher which is set up and working fine. It allows me to run a Python file in my browser and this Python file has HTML embedded in it. I have defined a click-able image by input type = "image" onclick = "some action"
. When I click the image it takes me to a JavaScript function which then performs window.location = "./move"
which then takes me to a Python function. The problem is that the browser window redirects to that function, i. e. localhost/scripts
becomes localhost/scripts/move
. Is it possible to execute the script without having the browser window change? I can post code if needs be.
-
Is that your own javascript function which resets window.location? What does the move function do?sureshvv– sureshvv09/30/2015 07:36:55Commented Sep 30, 2015 at 7:36
-
yes it basically justs redirects to the python function. Move allows for a servo motor to move. So i have an arrow button that when i click it causes a servo motor to turnAshill Chiranjan– Ashill Chiranjan09/30/2015 07:43:17Commented Sep 30, 2015 at 7:43
-
Can't you redirect back to /scripts at the end of move?sureshvv– sureshvv09/30/2015 07:46:31Commented Sep 30, 2015 at 7:46
-
Yes i can but i have video feed that keeps refreshing when i do that. So basically the whole page refreshes again and the video feed stops and startsAshill Chiranjan– Ashill Chiranjan09/30/2015 07:50:35Commented Sep 30, 2015 at 7:50
-
Why are you setting window.location? Can't you just call move()?sureshvv– sureshvv09/30/2015 07:50:46Commented Sep 30, 2015 at 7:50
|
Show 5 more comments
1 Answer
In fact, I've just found using Ajax/XmlHttpRequest is simple and work well for that, even if your server is a python SimpleServer style.
You just link this Javascript code from your button:
// send a request, but don't refresh page
xhttp = new XMLHttpRequest();
xhttp.open("GET", "?like", true);
xhttp.send();