Solved

How to read JSON response in JSP

Posted on 2015-01-18
2
301 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 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