像这样的简单调用:
type = 'theType';
category = 'theCategory';
$('#mydiv').load(
'${request.route_url('theUrl')}',
{type:type, category:category}
);
当我尝试访问 request.json_body
对象时,出现“无法解码 JSON 对象”错误。查看该请求,我可以看到它是一个 POST、X-Requested-With: XMLHttpRequest,并且正文是 type=theType&category=theCategory
,这当然不是 JSON。
我做错了什么?
我正在使用 Pyramid 1.3、Mako 0.72、jQuery 1.7.2
最佳答案
jQuery.load()
不发送 JSON。在 Pyramid 中,只需像使用普通 POST 请求一样访问表单变量即可:
request.params['type']
等等
关于带有 Pyramid 对象参数的 jQuery.load() 导致 "No JSON object could be decoded",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12356102/