我是网络开发的初学者。我试图用POST方法(没有jquery)发出ajax请求。以下是我的JS代码
function loadDoc() {
var Obj = {"user_Name":"testName"};
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("x").innerHTML =
this.responseText;
}
};
xhttp.open("POST", "/cgi-bin/Messapp/hostelapp.py", true);
xhttp.setRequestHeader("Content-Type", "text/json");
xhttp.send(JSON.stringify(Obj));
}
然后是我的python脚本
#!D:/python/python.exe
print("Content-Type: text/json\n\n")
import cgi, cgitb , re
cgitb.enable()
form = cgi.FieldStorage() #I am facing problem in this line
print(form["user_Name])
答案 0 :(得分:0)
您必须在ajax中添加以下标头,而不是json
grid-template-areas