【发布时间】:2016-02-15 05:34:02
【问题描述】:
我有一个关于 python flask 和 jquery 的应用程序。每当我尝试对某些事件调用日志记录机制时,我都会遇到以下问题。我在stackoverflow上没有找到可以解决这个问题的答案
POST http://localhost:5000/uploadLog/[object%20Object] 500 (INTERNAL SERVER ERROR)
在 frontend.js 文件中:
var eventObj = {
'eventType': 'Type1',
'eventDesc': event.target.href
};
$.post('/uploadLog/'+eventObj, function(response){
alert("successfully logged");
})
在controller.py中:
@app.route('/uploadLog/<eventObj>', methods=['POST'])
def uploadLog(eventObj):
loggerProg.updateLog(eventLogObj)
return jsonify({'status':'success'})
在 loggerProg.py 中:
def updateLog(eventObj):
parsed_obj = json.load(eventObj)
我尝试将 eventObj 写入文件,但文件中出现“[object Object]”。
【问题讨论】:
-
不能在 URL 中传递 Json 对象,将其作为数据发送。
标签: jquery python json rest logging