【发布时间】:2011-12-27 22:39:47
【问题描述】:
我正在尝试在我的应用中的 URL 之间发布 JSON。接收 URL 需要请求正文中的 JSON,并以请求正文中的 JSON 作为响应。问题是我似乎无法使用 Mootools Request.JSON 在正文中发送 JSON。这就是我所拥有的:
// formObj is an object constructed from a form
var request = new Request.JSON({
url: "/api/object.new",
urlEncoded: false,
onRequest: function(){
// swap submit button with spinner
},
onComplete: function(jsonObj) {
// work with returned JSON
},
body: JSON.encode(formObj)
});
request.setHeader("Content-Type", "application/json");
request.post();
服务器返回500错误:
BadValueError: Property name is required
这意味着request.name 正在返回None,这意味着服务器没有获取我的 JSON。
使用HTTPClient 将 JSON.encode(formObj) 的输出粘贴到正文字段中会产生所需的结果。
【问题讨论】:
-
尝试,正文:"x=" + JSON.encode(obj)
标签: javascript json post mootools