首页 > 解决方案 > AttributeError: 'NoneType' 对象没有属性 'get' //500(内部服务器错误)

问题描述

这不是从 crome 扩展发送任何数据,我正在尝试使用提到的 url 将 json 字符串发送到服务器,该 url 表示没有返回任何类型的对象,

 var xhr = new XMLHttpRequest();
 var ur = "http://127.0.0.1:8080/animal";
 var dat = {"subject":"subject"};
 xhr.open("POST", ur, true);
 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 xhr.onreadystatechange = function () {
     if (xhr.readyState == 4 && xhr.status == 200) {
         // do something with response
         console.log(xhr.responseText);
     }
};
xhr.send(dat);

         }
    };
    xhr.send(dat);

标签: javascriptpython-requests

解决方案


你不能用 发送一个对象xhr.send(),你需要序列化它。

var dat = 'subject=subject';

推荐阅读