我目前正在开发一个网页,该网页将接收项目列表的用户输入并将其发送到我的Python脚本。输入是要与更改的自身的早期版本进行比较的项目列表。该网页由以下html组成:
<body>
<div id="header">
<h1>Specialist Verification Report</h1>
</div>
<div id="report">
<div>
<form class="textbox">
<textarea id="specialistreport" name="username" placeholder="Paste Report Here" required></textarea>
</form>
</div>
<div>
<form class="textbox">
<textarea id="output" placeholder="Output" readonly></textarea>
</form>
</div>
</div>
<div id="footer">
<button id="send">SEND REPORT</button>
</div>
我在JavaScript中使用$ .ajax方法来处理文本框中的输入:
$('#send').click(function() {
$.ajax({
type: "POST",
url:"SVR.py",
data: {output: document.getElementById("specialistreport").value},
dataType: "json",
success: function(result) {
document.getElementById("output").value = result;
},
error: function() {
document.getElementById("output").value = "ERROR";
console.log("ERROR");
}
});
});
SVR.py:
import cgi
import cgitb
import json
import os
#Special exception handler. Displays detailed reports in Web browser if errors occur.
cgitb.enable()
#Bunch of irrelevant functions in between
#Initiate FieldStorage
form = cgi.FieldStorage()
if 'output' in form:
print "Content-Type: text/json; charset=ISO-8859-1\n"
print json.dumps("success")
else:
print "Content-Type: text/json; charset=ISO-8859-1\n"
print json.dumps("error")
这是我运行网页时得到的结果:
FieldStorage(None, None, ")
<type 'exceptions.TypeError'>: not indexable
args = ('not indexable',)
message='not indexable'
因此jQuery每次运行时都会运行$ .ajax成功函数,告诉我它找到了正常的文件,但是python打印了#34;错误&#34;并且似乎无法识别输出键。有人可以帮忙吗?