作者:dmcm0010 | 来源:互联网 | 2023-05-23 11:43
关于使用XMLHttpRequest()时接收数据,我有两个问题.客户端是Javascript.服务器端是python.
如何在python端接收/处理数据?
我如何回复HTTP请求?
客户端
var http = new XMLHttpRequest();
var url = "receive_data.cgi";
var params = JSON.stringify(inventory_json);
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.Onreadystatechange= function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
更新:我知道我应该使用cgi.FieldStorage(),但究竟是怎么回事?我的尝试以我的邮件请求收到服务器错误而告终.