myborobudur
myborobudur

Reputation: 4435

Post json-data from my own dojo-widget

I build my own widget with dojo as discussed here: Custom Widget

Now, I want to post the data on a certain event with the following code:

xhr.post({
  handleAs: "json",
  form: "answerForm",
  timeout: 15000,
  load: lang.hitch(this, "_onSubmitted", button),
  error: lang.hitch(this, "_onSubmitError", button)
});

I expected something like this in my xhr.post content: dojo.toJson(this)

How can I sent the data in json format to the server? Thanks!

Edit: added 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>

The data is correct in the html and the post arrives at the server but without the data.

Upvotes: 0

Views: 993

Answers (1)

Craig Swing
Craig Swing

Reputation: 8162

use postData in your xhrArgs.

xhr.post({
 handleAs: "json",
 postData:  dojo.toJson(obj),
 timeout: 15000,
 load: lang.hitch(this, "_onSubmitted", button),
 error: lang.hitch(this, "_onSubmitError", button)
});

Upvotes: 1

Related Questions