Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Parse HTTP Response with JS and pass its two values into a div

I'm currently trying to process an HTTP Response from the Google Sheets API and pass two specific cell values into an HTML Div each. Unfortunately, I'm a beginner with Javascript and can't quite modify my code to parse the request into usable JS objects and pass them to a value so I can use functions to write the values into their respective Div.

My Code so far:

var url = "https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/B2%3AC2?dateTimeRenderOption=FORMATTED_STRING&key=API_KEY";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function(){
if (xhr.readyState === 4){
console.log(xhr.status);
console.log(xhr.responseText);
}};

xhr.send();

Spreadsheet_ID and API_Key are placeholders.

The server returns an answer formatted like this:

{
"range": "Sheet1!B2:C2",
"majorDimension": "ROWS",
"values": [
[
  "Value 1",
  "Value 2"
]
]
}

My goal is to get Value 1 in a specific Div and Value 2 into a different one.

How do I process the HTTP response and at which point can I transfer the values into a variable?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I solved the problem by changing the way to get there. Parsing wasn't necessary, I simply cut the HTTP string to the characters I needed and used the JS .substring and .slice to first remove 67 characters before, then defining the limiting character at the end.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!