0

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());
  }
0

1 Answer 1

1

Your response type should be application/json.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.