passing json from servlet to dojo
Posted
by Moev4
on Stack Overflow
See other posts from Stack Overflow
or by Moev4
Published on 2010-04-02T16:57:56Z
Indexed on
2010/04/02
17:33 UTC
Read the original article
Hit count: 624
I am currently trying to pass a generated JSON string to dojo for parsing and am having some issues. The servlet simply writes it as a string as so:
response.getWriter().append("{ \"data\": {");
response.getWriter().append("\"type\": \"facing\",");
response.getWriter().append("\"score\": " + "\"" + score + "\",");
response.getWriter().append("\"count\":" + "\"" + count + "\"" );
response.getWriter().append("}}");
which prints as:
{"data":{"type":"facing","score":"10","count":"24"}}
And the parsing on the dojo end looks as so:
dojo.xhrPost({
url: url,
handleAs: "json",
load: function(data) {
alert(data);
/* Parse Not working */
alert(data.data[0].type);
},
error: function(error) {
alert("No dice")
}
});
The main issue is the data.data[0].type is returning nothing but when i print this out as text the json seems to be correctly formatted. Any help with this would be appreciated.
© Stack Overflow or respective owner