关于使用XMLHttpRequest()时接收数据,我有两个问题.客户端是javascript.服务器端是python.
客户端
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);
Run Code Online (Sandbox Code Playgroud)
更新:我知道我应该使用cgi.FieldStorage(),但究竟是怎么回事?我的尝试以我的邮件请求收到服务器错误而告终.
虽然像这样使用sprintf
sprintf("%.40s",str);
Run Code Online (Sandbox Code Playgroud)
我想给strlen(str)代替40这样的值.我该怎么做?我尝试用strlen(str)替换40,但是不起作用.给予像这样的价值
#define len strlen(str)
Run Code Online (Sandbox Code Playgroud)
并且使用%.len也不起作用,因为%.len用于"".