function egm() {
var url = 'district.php';
var egmHref='egmHref';
$.getJSON (url, function(data){
$.each (data, function(index, data){
$('#tablebody').append('<tr>');
$('#tablebody').append('<td>'+data.username+'</td>');
$('#tablebody').append('<td>'+data.password+'</td>');
$('#tablebody').append('<td>'+data.acclvl+'</td>');
$('#tablebody').append('<td id="anchor"></td>');
$('#anchor').append('<a class='" + egmHref +"' href='displayInfo.php?id="+ data.username +"'>View</a>');
$('#tablebody').append('</tr>');
});
});
}
Try this code