Skip to content

Instantly share code, notes, and snippets.

@DLzer
Created May 4, 2020 12:49
Show Gist options
  • Save DLzer/90dcee77df2f795b48d12d33fe6c7ed7 to your computer and use it in GitHub Desktop.
Save DLzer/90dcee77df2f795b48d12d33fe6c7ed7 to your computer and use it in GitHub Desktop.
External API to HTML via AJAX
<div>
<!-- Your List -->
<ul id="myList">
</ul>
</div>
<script>
// List jQuery variable
$list = $('#myList');
// AJAX Call using GET
$.ajax({
type: "GET",
url: "example.com",
success: function(resp) {
// If the call was successful, loop through the resp.data array
for(var i = 0; i < resp.data.length; i++) {
// for each index existing in resp.data, append the value as a list item to your list.
$list.append('<li>'+resp.data[i]+'</li>');
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment