The request itself:

var gender ='Male'; $.ajax({ url: '/main/main/public/go/' + gender, type: "GET", dataType: "json", success:function(data) { console.log(data); }, }); 

The answer comes like this:

{id: 4, name: "admin", email: "mort@gmail.com"}

How can I access the data and display it on an HTML page?

    1 answer 1

    Replace

     console.log(data); 

    on

     document.body.textContent = JSON.stringify(data); 
    • And how to apply to a particular property? For example id? - NEO
    • document.body.textContent = JSON.stringify (data) .id; - 0xSA
    • And if the request issued several [{"name": "admin", "avatar": "avatardefault.jpg", "id": 4}, {"name": "Maria", "avatar": "avatardefault.jpg" , "id": 6}], How to access a particular object? And what about his property? - NEO
    • And how exactly can I loop through every object with all the properties in the DOM? - NEO