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

195
Visualizações
How to convert XMLHttpRequest to json before entering the event?

It is possible to configure the json type information before entering the event, but it does not work for me, and I get errors constantly

function makeRequest6() {
var httpRequest = new XMLHttpRequest();
httpRequest.responseType = 'json'; 

httpRequest.onload = function() 
{
    //var json= JSON.parse(httpRequest.responseText); //i wnat avoid this line
    var json=httpRequest.responseText; // Here it failed
    console.log("Accepted");
    console.log(json);  
    var latestUsd=json.rates.USD; 
    console.log(latestUsd);
};
     
httpRequest.open('GET','http://api.exchangeratesapi.io/v1/latest?access_key=XXXXXXXXXXXXXXXXXXXX');
httpRequest.send();

}

ERROR:

main19.JS:253 Uncaught DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').
at XMLHttpRequest.httpRequest.onload (http://127.0.0.1:5500/lec_19_Ajax_%20getData_JSON/main19.JS:253:30)
about 4 years ago · Juan Pablo Isaza
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