0

I am newbie. I am sending the data from struts action using httpservlet response. What should i do to retrieve this value in javascript to set these values to an html element.

Used Struts action and httpservlet object to write to the response.

Gson gson = new Gson(); //using gson-2.3.1.jar 
//log.debug("Printing values ... ");
//log.debug(gson.toJson( languagesResponse.getLanguages()));

response.setContentType("application/json");
// Get the printwriter object from response to write the required json object to the output stream      
PrintWriter out = response.getWriter();
// Assuming your json object is **jsonObject**, perform the following, it will return your json object  
out.print(gson.toJson( languagesResponse.getLanguages()));
out.flush();

Let the json return the value as :

[{"stringCode":"default","numberCode":0,"__hashCodeCalc":false},{"stringCode":"en_US","numberCode":1,"__hashCodeCalc":false}]

I want to get this value for javascript elemtent.

k00989
  • 251
  • 2
  • 5
  • 16

1 Answers1

0

How you respond from HTTP server isn't relevant to this question as what you are asking is client-side code for that. Also this can be seen as duplicate of multiple questions from which you can get the answer to this like this (has nice overview of the idea). You can also check these two parts of jQuery for actual code examples: AJAX & DOM manipulation

Community
  • 1
  • 1
Roope Hakulinen
  • 7,326
  • 4
  • 43
  • 66