XMLHttpRequest调用后端python cgi脚本,python脚本没有响应

2024-06-16 15:04:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我用表单数据编写了一个简单的html文件,并使用XMLHttpRequest将数据发布到另一个pythoncgi脚本中,但是由于某些原因,python脚本没有完成它应该做的事情。在将数据从html传递到python之后,cgi脚本应该创建一个文本文件并在该文本文件中写入一行,但是在我单击“Run”按钮之后,文本文件就不会被创建了。知道为什么会这样吗?以下是html代码和python脚本:

----HTML----

<html>
<head> <title> TEST </title> </head>
<script type="text/javascript">
    function run(){
        var facPath = document.forms["inputParams"]["FacPath"].value;
        var facId   = document.forms["inputParams"]["IdName"].value;

        var xhttp; 
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        } else {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("response").innerHTML = this.responseText;
        }
        };
        xhttp.open("POST", "/cgi-bin/processRequest.py", true);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-
        urlencoded");
        xhttp.send("facPath="+facPath+"&facId="+facId);
    }
</script>

<body>
<P>
<form name="inputParams" >
Factor File Path <BR>
<input type="text" name="FacPath"> <BR><BR>

Factor ID Name <BR>
<input type="text" name="IdName"> <BR><BR>

<input type="button" value="Run" name="submit" onclick="run()">
</form>
</P>
<div id="response"> </div>
</body>
</html>

----Python cgi脚本----

^{pr2}$

我需要使python脚本可执行吗?还是其他原因?谢谢您。在


Tags: 数据textnamebr脚本varhtmltype