执行按钮点击一个python脚本 [英] Execute a python script on button click
问题描述
我有一个按钮的HTML页面,我需要执行一个Python脚本,当我们点击按钮,返回到相同的HTML页面的结果。
I have an HTML page with one button, and I need to execute a python script when we click on the button and return to the same HTML page with the result.
所以,我需要做一些验证的返回值,并执行一些动作。
So I need do some validation on return value and perform some action.
下面是我的code:
HTML:
<input type="text" name="name" id="name">
<button type="button" id="home" onclick="validate()" value="checkvalue">
JS:
function validate(){
if (returnvalue=="test") alert(test)
else alert ("unsuccessful")
}
我什么蟒蛇code正在做的是在文本框中输入的名称一些验证,并给出了返回状态。
What my python code is doing is some validation on the name entered in the text box and gives the return status.
但我需要的结果返回在同一页上,这样就可以与所有的细节以后做表单提交。任何帮助将AP preciated
But I need the result back on the same page, so I can do the form submission later with all the details. Any help will be appreciated
推荐答案
您应该使用Ajax,这与 jQuery的
You should use Ajax, which is easier with jQuery
$.ajax({
url: "/path/to/your/script",
success: function(response){
//here you do whatever you want with the response variable
}
});
和你应该阅读,因为它的jQuery.ajax页面有太多选择。
and you should read the jQuery.ajax page since it has too many options.
这篇关于执行按钮点击一个python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!