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

181
Views
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
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!