Listing users of a json api in a html table with javascript

0

Well, I'm pretty new to javascript and would like to know how to do the API call in JS and then I need a loop to list calls, they're in array in json. Can someone help me with this question?

code that I'm using to call the API

function listAtendimento() {
let body = '{"msg": "" }'

$.ajax({
    url: "link da api",
    type: 'post',
    dataType: 'json',
    data: body,
    contentType: "application/json; charset=utf-8",
    success: function (data) {

    }
});

}

    
asked by anonymous 30.05.2018 / 23:00

1 answer

0

Friend first you create the html corresponding to a list:

<ul id="lista"></ul>

After this within the success of your ajax loop in your array:

seuArray.map((el) => $('#lista').append("<li>"+ el.propriedadeQueSeraMostrada +"</li>"))

So you will loop your array and add a li for each element of your array in your list.

I hope I have helped.

    
31.05.2018 / 22:01