Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda