我想进行实时检查并在表中为每个结果创建一行。我所做的是当用户在文本字段中填写结果时,我使用 jquery 进行检查。
文本字段如下所示:
<input name="teamNaam" type="text" class="personeelField" id="teamNaam" onkeyup="return check_teamnaam();"/>
jquery是这样的:
<script language="javascript">
$(document).ready(function () {
$('#Loading').hide();
});
function wait(msecs) {
var start = new Date().getTime();
var cur = start
while (cur - start < msecs) {
cur = new Date().getTime();
}
}
function check_teamnaam() {
var teamNaam = $("#teamNaam").val();
if (teamNaam.length > 2) {
$('#Loading').show();
$.post("checkVriendenTeam.php", {
teamNaam: $('#teamNaam').val(),
}, function (response) {
//$('#Info').fadeOut();
// $('#Loading').hide();
var reactie = response;
var obj = jQuery.parseJSON(reactie);
console.log(obj.Coureur);
if (reactie == "Bezet") {
//fffkdf
} else {
$('#Info tr').has('td').remove();
$('#Info tr:last').after('<tr class="tabeltitel" height="30"><td width="5%">#</td><td width="29%" class="tabeltitel">' + response.Teamnaam + '</td><td width="23%" class="tabeltitel">' + response.Manager + '</td><td width="24%" class="tabeltitel">Vrienden worden</td></tr>');
}
});
return false;
}
}
</script>
它正在检查“checkVriendenTeam.php”并返回结果。结果如下所示:
[{"Teamnaam":"test"},{"Teamnaam":"test2"},{"Teamnaam":"test3"}]
我用 php 代码得出这个结果:
if($_REQUEST)
{
$teamNaam = $_REQUEST['teamNaam'];
$query = "select * from spelers where Teamnaam LIKE '".strtolower($teamNaam)."%'";
$results = mysql_query( $query) or die('ok');
if(mysql_num_rows(@$results) > 0) // not available
{ $response = array();
while($inhoud = mysql_fetch_array($results)) {
$response[]['Teamnaam'] = $inhoud['Teamnaam'];
}
$jsonData = json_encode($response);
echo $jsonData;
}
else
{
echo 'no result';
}
}
但它只会创建一行没有任何数据(未定义)。那么我需要做什么才能获得 3 行?