Solved

How to read JSON response in JSP

Posted on 2015-01-18
2
288 Views
Last Modified: 2015-01-19
Hi guys,

In JSP page, I am calling dojo/Ajax as below:

                 var number1=43;
            params.input1 = number1;
            var xhrArgs1 = {
              url : 'AJAXComand',
                  handleAs : 'text',
                content : params,
                preventCache:false,
                load:function(data){
                    //alert('success!');
                    handleResponse(data);
                 },
                 error: function(error){
                   alert(error);
                  },
                 timeout:100000
            };
                dojo.xhrPost(xhrArgs1);
      
      }
      function handleResponse(data){
            data = data.replace("/*", "");
                  data = data.replace("*/", "");  
                  var obj = eval('(' + data + ')');
          console.debug(obj);
          }

----------
If I see in browser debugger: I see this

(
 {
  input1:["43"],
  input2:["21"],
  message1:"Message 1 Data",
  message2:"This is another test data."
 }
)
@ http://localhost/app_home/
-----------
How can I get value of message1 and message2 and set to div of id "test1"

something like this???
document.getElementById("test1").innerHTML = data.message1;
0
Comment
Question by:student237
2 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 40557018
Given that you already have obj, if I'm reading things correctly, try

document.getElementById("test1").innerHTML = obj.message1

Open in new window

0
 

Author Closing Comment

by:student237
ID: 40557891
Thank you for the response.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now