Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to read JSON response in JSP

Posted on 2015-01-18
2
Medium Priority
?
326 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 2000 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

Independent Software Vendors: 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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

927 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