小编Ice*_*man的帖子

使用XMLHttpRequest()时如何在python中接收POST数据

关于使用XMLHttpRequest()时接收数据,我有两个问题.客户端是javascript.服务器端是python.

  1. 如何在python端接收/处理数据?
  2. 我如何回复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);
Run Code Online (Sandbox Code Playgroud)

更新:我知道我应该使用cgi.FieldStorage(),但究竟是怎么回事?我的尝试以我的邮件请求收到服务器错误而告终.

javascript python xmlhttprequest

7
推荐指数
1
解决办法
4581
查看次数

使用%.s的sprintf用法

虽然像这样使用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用于"".

c printf

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

javascript ×1

printf ×1

python ×1

xmlhttprequest ×1