
Some parts of this message have been removed.
Learn more about Nabble's
security policy.
I send json to the server using xhrPost by assigning the json a parameter.
ie.
dojo.xhrPost({
url: './blah',
content: { json: dojo.toJson(myJsonObject) }
});
On the server i just get the "json" parameter value and deserialize it.
> From:
jochen.luig@...> To:
dojo-interest@...> Date: Thu, 7 Aug 2008 13:38:50 +0200
> Subject: [Dojo-interest] Sending JSON Data to a server
>
> Hi,
>
> I've recently started to look into Dojo. On the server side I have an
> App that automatically deserializes Data provided by the client and
> serializes it before sending a response. My format of choice is JSON.
> Alas, the dojo.xhrPost seems to insist on sending the data as key=value
> pairs separated by a '&' which on one hand lead my App to believe there
> wasn't any POST data (as it expects JSON and thus finds nothing to
> serialize). On the other hand I can't comfortably send deeply nested
> data to the server. By chance I came across dojo.rawXhrPost which does
> the trick if used in this way (I couldn't get dojo.xhrPost to behave in
> a similar way):
>
> dojo.rawXhrPost({
> url: "http://path.to/whatever",
> handleAs: "json",
> postData: json_string,
> headers: {"Content-Type": "application/json"},
> handle: function (data, args) {
> if (typeof(data) == "error") {
> // error handling
> } else {
> // do something
> }
> }
> });
>
> Although this works quite well for me so far, I have a few questions:
>
> 1.) dojo.rawXhrPost isn't documented exhaustively. E.g. the (quite
> recent) Addison Wesley Dojo Book
> (http://www.amazon.com/Dojo-JavaScript-Library-Applications-Developers/dp/0132358042/ref=pd_bbs_sr_3?ie=UTF8&s=books&qid=1218108346&sr=8-3 ) doesn't mention the function at all. Is it likely to be deprecated anytime soon (or is it already)? If so, what would be a reasonable alternative?
> 2.) having to override the Content-Type header by hand seems quite
> "hackish" to me. Is there another way?
> 3.) the conditional in the handler function (I found that one in a
> tutorial) always gets into the "else" part even if it gets back a 405
> response code from the server. Is that expected behaviour? I would have
> expected anything in the 400-range to result in an error. How can I do
> different things according to specific http response codes?
>
> Thanks
>
> Jochen
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
>
Dojo-interest@...> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
to the movies
Shout your Messenger buddies
_______________________________________________
FAQ:
http://dojotoolkit.org/support/faqBook:
http://dojotoolkit.org/docs/bookForums:
http://dojotoolkit.org/forumDojo-interest@...
http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest