Reputation: 1535
I am returning a PHP array back to a JQuery call for appending into a div called "name-data". I want my array to be listed vertically, so I concatenate a br tag in the PHP however, when it gets to the HTML page the br is not being rendered, it just comes out as text. I have tried the various forms of br all without luck.
I am new to JQuery - What am I doing wrong ? Many Thanks !
PHP:
$result = mysqli_query($con,"SELECT FirstName FROM customer limit 5");
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName']."<br />";
}
JQuery:
$('input#name-submit').on('click',function(){
var name = $('input#name').val();
if($.trim(name) !=''){
$.post('search.php',{name:name}, function(data){
$('div#name-data').text(data);
});
}
});
HTML
Name:<input type="text" id="name">
<input type="submit" id="name-submit" value="grab">
<div id="name-data"> </div>
Upvotes: 0
Views: 132
Reputation: 44831
Also, if the <br>
is the last thing in the div, most browsers won't actually render a break. You need something after it, like this: <br>
Upvotes: 0
Reputation: 8492
Try replacing .text()
with .html()
.
$('div#name-data').html(data);
Also, for the love of Cthulhu, parameterize your MySQL query. That's a SQL injection just waiting to happen.
Upvotes: 5