Solved

How to read JSON response in JSP

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This article discusses how to create an extensible mechanism for linked drop downs.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.

805 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