Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:22:40+00:00 2026-05-31T00:22:40+00:00

I’ve got a response that sends back an entire table. N number of rows

  • 0

I’ve got a response that sends back an entire table. N number of rows with 7 cells in each row. So I end up with nX7 responses. Apparently, I should be using JSON to handle the string appropriately. I’ve found tutorials on how to create a JSON object, but not so much on how to send it via ajax and how in sending it through ajax, the jsp knows to fill the JSON object with the responses… In other words,

  1. I create JSON object in javascript (check)
  2. place JSON object in the ajax code (confused)
  3. response with JSON object filled (confused)
  4. Parse JSON object so I can get at the data easily (maybe confused, we’ll see after steps 2/3)

I am not using jquery as I’m still learning and jquery’s syntax is confusing currently.

var sweekStart = document.getElementById("weekStart").value;
var smonth = document.getElementById("month").value;
var syear = document.getElementById("year").value;      

var xmlhttp;
if (window.XMLHttpRequest)  
     {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();  
     } 
     else
      {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }  

var url = "empTableRepop.jsp?weekStart=" + encodeURIComponent(sweekStart)+"&month="+encodeURIComponent(smonth)+"&year="+encodeURIComponent(syear);
xmlhttp.open("POST",url,true);
//alert("made it to open");
xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4){             
            //alert(xmlhttp.responseText);
            var test = xmlhttp.responseText;            
            reFillTable(test);  


        }
    }       

xmlhttp.send(null);

The variable “test” (yea, bad name but it’s temporary) is the object I want converted from a standard var to a JSONobject. If I understand correctly, JSON will already have the string parsed when it receives the response. I realise I can change “function()” to be directly “reFillTable(test)” but given the path it took me to get it working I ended up with that somehow lol. Will fix once everything is working properly.

EDIT:

This is how I “display” the information from the jsp/java file.

//Name Cell
        out.println(empName);           

        //Mondays Hours
        out.println(hoursArr[0]);           

        //Tuesdays Hours
        out.println(hoursArr[1]);               

        //Wednesdays Hours
        out.println(hoursArr[2]);   

        //Thursdays Hours
      out.println(hoursArr[3]); 

        //Fridays Hours
        out.println(hoursArr[4]);           

        //Total hours Cell
        out.println(PTOAmt);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:22:42+00:00Added an answer on May 31, 2026 at 12:22 am

    Assuming that your serverresponse is already working, this gives you the JavaScript object from the received JSON.

    var test = JSON.parse( xmlhttp.responseText );
    

    To clarify: There is no explicit “JSONObject” in JavaScript. JSON stands for JavaScript Object Notation and is simply a shorthand for writing normal JavaScript objects. It became, however, popular as a means of serializing data to send through AJAX-request.

    In the end the server just sends a string in JSON format, which you on the other hand have to parse again (by JSON.parse()) in order to have an object representing the data send.


    Just to add: JSON.stringify() is the operation in the other direction. Creating a string out of a JavaScript object.


    With respect to the edit:

    As said in the comment, this does not create valid JSON (have a look @ json.org for an overview).

    So now you have some choices:

    1. Use a library like GSON to encode your data.

    2. Parse your data by hand in JavaScript. (I would not recommend this).

    3. Create a valid JSON string manually.

    The code for the third option, may look like this:

    // start the JSON object
    out.print( "{" );
    
    //Name Cell
    out.println( "\"empName\":\"" + empName + "\"," );
    
    // start an array for the next few values
    out.print( "\"hours\": [" );
    
    out.print(hoursArr[0] + "," );
    out.print(hoursArr[1] + "," );
    out.print(hoursArr[2] + "," );
    out.print(hoursArr[3] + "," );
    out.print(hoursArr[4] + "," );
    
    // end the array
    out.print( "]," );        
    
    //Total hours Cell
    out.print( "\"PTOAmt\":\"" + PTOAmt + "\"");
    
    // end the JSON
    out.print( "}" );
    

    This assumes that PTOAmt is a string as well.

    On the long run you should use a library like mentioned in option (1) to handle the encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.