[英]How to run a Python script upon button click using mod_python without changing browser window
I am using mod_python
publisher which is set up and working fine. 我使用的是
mod_python
发行商,它已经设置好并且工作正常。 It allows me to run a Python file in my browser and this Python file has HTML embedded in it. 它允许我在浏览器中运行Python文件,并且该Python文件中嵌入了HTML。 I have defined a click-able image by
input type = "image" onclick = "some action"
. 我通过
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. 当我单击图像时,它将带我到一个JavaScript函数,该函数然后执行
window.location = "./move"
,然后将我带到Python函数。 The problem is that the browser window redirects to that function, ie localhost/scripts
becomes localhost/scripts/move
. 问题是浏览器窗口重定向到该函数,即
localhost/scripts
变为localhost/scripts/move
。 Is it possible to execute the script without having the browser window change? 是否可以在不更改浏览器窗口的情况下执行脚本? I can post code if needs be.
如果需要,我可以发布代码。
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. 实际上,我发现使用Ajax / XmlHttpRequest很简单,并且即使您的服务器是python SimpleServer样式,也可以很好地工作。
You just link this Javascript code from your button: 您只需从按钮链接此Javascript代码:
// send a request, but don't refresh page
xhttp = new XMLHttpRequest();
xhttp.open("GET", "?like", true);
xhttp.send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.