T
T
Tati122019-05-15 16:09:58
JavaScript
Tati12, 2019-05-15 16:09:58

How to display the necessary json elements (variables) on the front end (javascript)?

Good day!
I really need help ....
Here is such a js code

var userName = "name";
var passWord = "pass";

function authenticateUser(user, password)
{
    var token = user + ":" + password;

    var hash = btoa(token); 

    return "Basic " + hash;
}

function CallWebAPI() {
(код html   <div>
                <div id="response">
                
                </div>
                <input type="button" class="btn btn-primary" value="Call Web API" onclick="javascript:CallWebAPI();" />)
   
    var request = new XMLHttpRequest();
    request.open("GET", URL, false);
    request.setRequestHeader("Authorization", authenticateUser(userName, passWord));  
    request.send();
    // view request status
    alert(request.status);
    response = request.responseText;
    console.log(response);
}

I'm trying to get the data I need from json, but nothing happens, each variable writes undefined..

var some = document.getElementById("some");
some.innerHTML = response.name json variable;
or
$("#some").text(response[0].name json variable + "\n" );


I can not figure out what the problem is ... I will be very glad to help !!! Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question