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