javascript - Text not marking up -
i writing page allows tournament director (td) add players event. when td goes search player want search results appear on keyup below search input (without needing refresh page). @ stage have 2 php pages , 1 js page , have live search happening, output not getting marked up. have written piece of code convert php $_session[''] array javascript array, brain frying , i'm not sure go here.
i want processed version of code output (presuming sql returns 1 player named john smith)
<tr></td> 123 </td><td> john smith </td></tr>
my main php page has:
<table border='1px'> <tr><th colspan='6'> <?php echo ($ename . " - " . $vn); ?></th></tr> <tr><th>player id</th> <th>player name</th> <th>place</th> <th>points</th> <th>cash</th> <th>ticket?</th></tr> <tr><td colspan='3'>search <input type='text' id='newsearch'</input> </table> <br> <div id="newsearch-data"> </div> <script> var players = []; </script> <?php //makes php array js array foreach ($_session['players'] $id){ echo "<script> players.push('" . $id . "') </script>"; } ?> <script src="http://code.jquery.com/jquery-1.8.0.min.js"> </script> <script src="global.js"> </script>
js page:
$('input#newsearch').on('keyup', function(){ var newsearch = $('input#newsearch').val(); if ($.trim(newsearch)!= "") { $.post('newsearch.php', {newsearch: newsearch}, function(data) { $('div#newsearch-data').text(data); }); } });
and 2nd php page
<?php session_start(); unset($_session['players']); if (isset($_post['newsearch']) === true && empty($_post['newsearch'] === false)){ require 'dbconnect.php'; $term = $_post['newsearch']; $terms = "%" . $term . "%"; $_session['players'] = array(); $query = ("select * players username '$terms'"); $run_query = mysqli_query($dbcon, $query); while ($dbsearch = mysqli_fetch_assoc($run_query)) { array_push ($_session['players'],$dbsearch['playerid']); echo "<tr><td>" . $dbsearch['playerid'] . "</tr></td>"; }}?
how can output new row on html table rather raw html code?
replace $('div#newsearch-data').text(data);
with $('div#newsearch-data').html(data);
$.text()
escapes input string , should use when know input string, , want preset "as is". if input includes actual html want inject dom, $.html()
friend :-)
Comments
Post a Comment