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

81
Views
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 answers
Answer question

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 Report

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