Python中文
首页
教程
问答
标签
搜索
登录
注册
Tornado无法读取json ajax请求
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>使用<code>ajax</code>我试图将数据发送到我的Tornado服务器,这是我的JQuery:</p> <pre><code>$("#addTask").submit(function(e){ e.preventDefault(); var add = $('#addProject').val(); var added={projectAdded:add}; $.post("/task", JSON.stringify(added), function(data){ window.location.reload(true); }); }); </code></pre> <p><code>$('#addProject').val();</code>的值来自输入文本字段:</p> ^{pr2}$ <p>在我的Tornado服务器中,我有:</p> <pre><code> class TaskAddHandler(BaseHandler): def post(self): addProj = json.loads(self.request.body) print 'NEW TASK', addProj </code></pre> <p>但这给了我一个错误:<code>raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded</code>,而不是输入文本字段的值。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我认为您需要发送一个JSON字符串作为数据,而不是对象。尝试JSON.stringify({pro添加对象:添加})而不仅仅是对象。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
在python3中使用Scipy pearsonr函数
7 回答
在Python3中使用scipy对多个lorentzian进行数据拟合
8 回答
在Python3中使用Script=argv
7 回答
在python3中使用selenium webdriver进行未解析的回溯
3 回答
在python3中使用selenium和phantomjs的网页截图之前如何等待?
7 回答
在Python3中使用Selenium和Requests模块从网页获取文件
6 回答
在python3中使用SIGINT终止函数
10 回答
在Python3中使用SIGTERM时,允许进程完成而不是中断
5 回答
在python3中使用smtplib发送XML内容
6 回答
在python3中使用socket库(RFCOMM模式)重新连接蓝牙设备?
4 回答
在python3中使用sounddevice和numpy编写wav文件
9 回答
在python3中使用Sqlalchemy插入MySQL查找类型错误的原因
1 回答
在python3中使用sqlite、pandas和sqlalchemy很难让rollback工作
5 回答
在python3中使用SQLite的FTS3/4
10 回答
在Python3中使用struct.calcsize()和len()有区别吗?
2 回答
在python3中使用substring函数时发生TypeError
7 回答
在Python3中使用Tkinter entry小部件写入串行设备
7 回答
在python3中使用tkinter时,如何在每次按下函数时获得运行该函数的按钮?
7 回答
在python3中使用tkinter的子帧
8 回答
在Python3中使用tryexcept块时,如何避免使用未初始化的变量?
4 回答