The server servlet code is below(return to client);
JSONWriter jw = new JSONWriter(response.getWriter()); try { jw.array(); jw.object(); jw.key("result").value(result); jw.endObject(); jw.endArray(); } catch (JSONException e) { log.error("JSON Exception:", e); }
And the client file JS in fold clientlibraryfold "xxx.js" not JSP page is below:
CQ.Ext.Ajax.request({ url: CQ.HTTP.externalize("/bin/customer"), method: "GET", success: function(response) { var info = response.responseText; alert(info);//[{"result":1}] var ack = info.result1;//undefined error alert(ack); }, failure: function(response) { } });
So how to get the Key "result" value? I did try to use couple of way but fail. Anybody know that? Please comment it, thanks a lot.
Solved! Go to Solution.
Views
Replies
Total Likes
We have a community article that shows how to work with JSONWriter - this is exactly what you are looking for.
http://helpx.adobe.com/experience-manager/using/using-jsonwriter-objects-display-cq.html
Views
Replies
Total Likes
You need to parse the resposne text into a JavaScript object. Something like
var obj = CQ.Ext.util.JSON.decode(response.responseText); var ack = obj.result;
Views
Replies
Total Likes
It not work according to your way :(
Views
Replies
Total Likes
bbboy2014 wrote...
It not work according to your way :(
Sorry, I misread your code. I missed that the JSON is an object wrapped in an array. I should have written
var ack = obj[0].result;
Views
Replies
Total Likes
justin_at_adobe wrote...
bbboy2014 wrote...
It not work according to your way :(
Sorry, I misread your code. I missed that the JSON is an object wrapped in an array. I should have written
var ack = obj[0].result;
Exactly
Views
Replies
Total Likes
We have a community article that shows how to work with JSONWriter - this is exactly what you are looking for.
http://helpx.adobe.com/experience-manager/using/using-jsonwriter-objects-display-cq.html
Views
Replies
Total Likes
Thanks for your reply, i gain most again.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies