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

Asked

Viewed 326 times

0

Well I am very new in javascript and I would like to know how to make the API call in JS and soon after I need a loop to list calls, they are in array in json. Can someone help me with this doubt

code I’m using for API call

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

    }
});

}

  • 1

    Hello Victor, post the code you already developed to receive more help and if you want to take a look here https://answall.com/tour

1 answer

1


Friend first you create the html corresponding to a list:

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

After that inside the Success of your ajax make the loop in your array:

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

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

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.