I am trying to format the data I receive from my database using Ajax via my PHP script, as a table. I get a reply but the table tags are shown in my div#name-data, instead of the actual table. How can I resolve this issue?
AJAX
$('input#name-submit').on('click',function(){
var name = $('input#name').val();
if($.trim(name)!=''){
$.post('ajax/name.php',{name:name},function(data){
$('div#name-data').text(data);
});
}
});
PHP
$query = mysql_query(" SELECT * FROM employee WHERE first_name='".mysql_real_escape_string(trim($_POST['name']))."'");
$row = mysql_fetch_array($query);
echo $row['emp_id'].$row['last_name'];
You are returning tags in your result. You have used the
textmethod to display the result and not thehtmlmethod. You should change the lineto
See here for the difference between text method and the html method.