这个javascript下拉列表在PHP应用程序中自动完成Windows本地服务器上的工作,但是当我在Linux服务器上应用程序时尝试这个功能时没有任何反应。也许我应该改变现场方法?但是如何?
这是javascript
<script type="text/javascript">
$(function(){
$(".search_keyword").keyup(function()
{
var search_keyword_value = $(this).val();
var dataString = 'search_keyword='+ search_keyword_value;
if(search_keyword_value!='')
{
$.ajax({
type: "POST",
url: "search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}
return false;
});
$("#result").on("click",function(e){
var $clicked = $(e.target);
var $name = $clicked.find('.country_name').html();
var decoded = $("<div/>").html($name).text();
$('#search_keyword_id').val(decoded);
});
$(document).o("click", function(e) {
var $clicked = $(e.target);
if (! $clicked.hasClass("search_keyword")){
$("#result").fadeOut();
}
});
$('#search_keyword_id').click(function(){
$("#result").fadeIn();
});
});
</script>
这是search.php
include('db.php');
if(isset($_POST['search_keyword']))
{
$search_keyword = $polaczenie->real_escape_string($_POST['search_keyword']);
$sqlCountries="SELECT name FROM shop WHERE name LIKE '%$search_keyword%'";
$resCountries=$polaczenie->query($sqlCountries);
if($resCountries === false) {
trigger_error('Error: ' . $polaczenie->error, E_USER_ERROR);
}else{
$rows_returned = $resCountries->num_rows;
}
$bold_search_keyword = '<strong>'.$search_keyword.'</strong>';
if($rows_returned > 0){
while($rowCountries = $resCountries->fetch_assoc())
{
echo '<div class="show" align="left"><span class="country_name">'.str_ireplace($search_keyword,$bold_search_keyword,$rowCountries['nazwa']).'</span></div>';
}
}else{
echo '<div class="show" align="left">Brak</div>';
}
}