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

85
Visualizações
How I can output data from request on my SPA using native XMLHttpRequest?

I have a conditional html page and a conditional api.

GET request for user data in my api looks like this:

URL: {host}/user
Method: GET

Headers
- Content-Type: application/json
- Authorization: Bearer {token}

And the response:

Status: 200
Content-Type: application/json
Body:
{
    "first_name": "Ivan",
    "last_name": "Ivanov",
    "phone": "89001234567",
    "document_number": "1224567890"
}

How I can send the requests and output response data using XMLHttpRequest?

I try to use xhr.response() and it's work good, but when I try to xhr.response()['first_name'] it don't work properly

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I see two options given you have native JavaScript and jQuery available

The Fetch API

Or the older "standard" of jQuery.

$.ajax({url: "demo_test.txt", success: function(result){
    $("#div1").html(result);
  }});
about 4 years ago · Juan Pablo Isaza Relatório

0

The solution was very simple.

Standart output of xhr.response(), where xhr = new XMLHTTPRequest(); not a JSON, so I need to put xhr.responseType = 'json' before xhr.open('POST', url)

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