Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phumberdroz/e392e7e0814a9bb53ba594d66f5312ad to your computer and use it in GitHub Desktop.
Save phumberdroz/e392e7e0814a9bb53ba594d66f5312ad to your computer and use it in GitHub Desktop.
Javascript create table
function queryapi(value) {
if (value.length >= 3 || value.length == 0) {
var url = "api/customers/?search=" + value;
$.getJSON({
type: 'get',
url: url,
success: function(data) {
var newtable = "<tbody>";
data.forEach(function(element) {
newtable = newtable + "<tr><td>" + element.name + "</td><td>" + element.phone + "</td></tr>"
})
console.log(newtable + "</tbody>")
document.getElementById('table').innerHTML = newtable + "</tbody>"
},
error: function(xhr, textStatus, errorThrown) {
console.log(errorThrown)
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment