Reputation: 3
I am making an ajax request where I will type name in input box to search data from db, It's working fine,
<script>
$(document).ready(function(){
$('input#name-submit').on('click', function() {
var nameVar = $('input#name').val();
if($.trim(nameVar) != ''){
$.post('records.php', {name: nameVar}, function(data){
$('div#name-data').text(data);
});
}
});
});
</script>
----php
if(isset($_POST['name'])){
$name = $_POST['name'];
echo $name;
Now the problem is when I embed the html into php and echo it, It prints the html also
echo "<div class='tblDiv'>";
echo "</div>";
result: <div class='tblDiv'> Name </div>
how to avoid that and get the result in style?
Upvotes: 0
Views: 67
Reputation: 388416
You need to use .html() instead of .text()
$('#name-data').html(data);
.text()
will not parse the html
content, it will escape the html
and print the passed value as it is
Upvotes: 4