我正在尝试通过以下方式将数据发布到 App Engine:
sendMessage = function(path, data) {
$.ajax({
type: "POST",
url: path,
data: data,
contentType: "application/json",
dataType: "json",
failure: function(errMsg) {
alert(errMsg);
},
success: function(result,status,xhr){
alert(result);
}
});
};
sendMessage('/chatMessage', {"message": "aaaa"});
接收代码:
class ChatMessage(webapp2.RequestHandler):
def post(self):
user = users.get_current_user()
message = self.request.get("message", "fail")
logging.error('RequestBody:' + str(self.request.body))
logging.error('Message:' + message)
日志消息:
ERROR 2013-05-18 16:23:31,954 channels.py:52] RequestBody:message=aaaa
ERROR 2013-05-18 16:23:31,956 channels.py:53] Message:fail
INFO 2013-05-18 18:23:31,983 server.py:585] default: "POST /chatMessage HTTP/1.1" 200 2
显然,消息在服务器上完好无损,因为它说message=aaaa
但是为什么我不能从请求中“获取”消息?