Created
April 7, 2016 13:44
-
-
Save phumberdroz/e392e7e0814a9bb53ba594d66f5312ad to your computer and use it in GitHub Desktop.
Javascript create table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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