Reputation: 569
I'm unable to get data back from ajax request from java servlet using Json object..here is the code below we are using channel api in google app engine .we need to implement chat application.
displayFriendList = function() {
var txt = document.createElement("div");
txt.innerHTML = "<p> Logged in as <b>" + userid
+ "</b><p><hr />";
document.getElementById("friendlistdiv").appendChild(
txt);
var dataString ='userId='+userid;
$.ajax({
type : "POST",
url : "/OnlineUserServlet",
data : dataString,
success : function(html) {
alert(html.frndsList[0].friend);
}
});
};
Java Servlet Code:
while(friendList.hasNext()){
friend = friendList.next() ;
if(!friend.equals(user)){
Map<String, String> state = new HashMap<String, String>();
state.put("friend", friend);
state.put("type","updateFriendList");
state.put("message",user);
state1.add(state);
message = new JSONObject(state);
channelService.sendMessage(
new ChannelMessage(friend,message.toString()));
}
i++;
}
Map<String, String> statejason = new HashMap<String, String>();
statejason.put("friendsList", state1.toString());
//System.out.print("hello"+message.toString());
response.setContentType("text/plain");
response.getWriter().print(statejason.toString());
}
Upvotes: 0
Views: 519