2012-10-08 86 views
0
<script type="text/javascript" src="js/jquery.js"></script> 
<script type='text/javascript' src='js/jquery.autocomplete.js'></script> 
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" /> 

自動完成第一次工作時,頁面刷新,我輸入4個字符如果我退格並從開始輸入其他字符它不起作用,有人可以幫助我爲什麼會出現這種情況自動完成僅第一次工作

$().ready(function() { 


    $("#customername").autocomplete("ajax/customerlist.php", { 
     width: 260, 
     dataType: 'json', 
     matchContains: false, 
     selectFirst: false, 
     minlength:4, 
     parse: function(data) { 

       var array = new Array(); 
       for(var i=0;i<data.items.length;i++) 
       {  //alert(data.items[i].name); 
         array[array.length] = { data: data.items[i], value: data.items[i], result: data.items[i].name }; 
       } 
       return array; 
     }, 
     formatItem: function(row) {      
       var name = ''; 
       if (row.first_name && row.last_name) 
         name = '('+row.first_name+', '+row.last_name+')'; 
       else if (row.first_name) 
         name = '('+row.first_name+')'; 
       else if (row.last_name) 
         name = '('+row.last_name+')'; 

       return row.name+' '+name; 
     } 
    }); 

    $('#customername').result(function (event, data, formatted) { 
     $("#cust").val(data.id); 
     var add= data.add1+data.add2; 
     $("#address").val(add); 
     $("#email").val(data.email); 
     $("#phone").val(data.phone); 
     $("#mobile").val(data.mobile); 

    }); 
}); 

的PHP代碼是

$getuser=$db->execute("select * from `customer` where customer_name like '%".mysql_$_REQUEST['q']."%' "); 


while($getuserlist = $db->fetchAll($getuser)) { 

$list['items'][]=array('name' => $getuserlist['customer_name'],'id'=>$getuserlist['customer_id'],'add1'=>$getuserlist['add1'],'add2'=>$getuserlist['add2'],'city'=>$getuserlist['city'],'state'=>$getuserlist['state'],'pincode'=>$getuserlist['pincode'],'email'=>$getuserlist['email'],'phone'=>$getuserlist['phone'],'mobile'=>$getuserlist['mobile']); 

} 

echo json_encode($list); 
+0

類型檢查你的PHP錯誤日誌和JavaScript錯誤控制檯,它將運行。 – MrCode

回答

2

改變這種

$().ready(function() { 

$("#customername").keyup(function() { 

,只要您在"#customername"

相關問題