我使用dojo构建我自己的小部件,如下所述:Custom Widget
现在,我想使用以下代码在特定事件上发布数据:
xhr.post({
handleAs: "json",
form: "answerForm",
timeout: 15000,
load: lang.hitch(this, "_onSubmitted", button),
error: lang.hitch(this, "_onSubmitError", button)
});
我在xhr.post content: dojo.toJson(this)
如何以json格式将数据发送到服务器? 谢谢!
编辑:添加了html-template
<form id="answerForm" action="${url}">
<div data-dojo-attach-point="selectionAnswerWidget" data-dojo-type="dijit.layout.ContentPane"
data-dojo-props="region: 'bottom'">
<div data-dojo-type="dojo.store.Memory" data-dojo-id="answerStore"
data-dojo-props="data: [{id: 'YES', name: 'yes'}, {id: 'NO', name: 'no'}, {id: 'UNANSWERED', name: 'unanswered'}]"></div>
<input data-dojo-type="dijit.form.FilteringSelect" value="${answer}"
data-dojo-props="store:answerStore, searchAttr:'name'" data-dojo-attach-point="answerSelection" />
</div>
<div data-dojo-attach-point="textAreaAnswerWidget" data-dojo-type="dijit.layout.ContentPane"
data-dojo-props="region: 'top'">
<textarea data-dojo-attach-point="commentNode" rows="5" cols="50" data-dojo-type="dijit.form.SimpleTextarea"
data-dojo-props="selectOnClick:true">${comment}</textarea>
</div>
html中的数据是正确的,帖子到达服务器但没有数据。
答案 0 :(得分:1)
在xArgs中使用发布数据。
xhr.post({
handleAs: "json",
postData: dojo.toJson(obj),
timeout: 15000,
load: lang.hitch(this, "_onSubmitted", button),
error: lang.hitch(this, "_onSubmitError", button)
});