I am expecting a list of values from my php code
PHP CODE:
$warriors = array();
foreach($result as $names){
$warriors[] = $names;
}
echo json_encode($warriors);
JS FUNCTION:
function getWarriors() {
$.ajax({
url: "display_warriors.php",
datatype:"json",
success: function(data) {
var toAppend = '';
if(typeof data === "object"){
for(var i=0;i<data.length;i++){
var warrior = data[i];
toAppend += '<tr>';
toAppend += '<td>'+data[i]['warrior_id']+'</td>';
toAppend += '<td>'+data[i]['warrior_name']+'</td>';
toAppend += '<td>'+data[i]['warrior_type']+'</td>';
toAppend += '</tr>';
}
$("#listWarriors table").append(toAppend);
}
}
});
return false;
}
HTML CODE TO CALL FUNCTION
<li><a href="#listWarriors" onclick="return getWarriors()">Warrior List</a></li>
When I click the a tag it does not display what I am expecting, what could be wrong