JQuery UI Autocomplete Ajax

Комментарии ()

html

<link rel="stylesheet" type="text/css" href="{www}css/ui-lightness/jquery-ui-1.10.3.custom.min.css" />
<script src="{www}js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="{www}js/jquery-ui-1.10.3.custom.js" charset="utf-8" ></script>

<script>
$(document).ready(function(){
 
    $("#login").autocomplete({
	source: function(request, response) {
                  var id = this.element.attr('id');                
                  $.ajax({
                  url: "{www}",
                  data: { q: $("#login").val(),
		  mod: 'admin',
		  act: 'users_balans',
		  op: 'login_autocomplete'},
                  dataType: "json",
                  type: "POST",
                  success: function(data){
                      response(data);
                  }
                });
              },
      minLength: 1
    });
});
</script>

php

<?php

/* @var $sql Sql */
/* @var $error Error */
/* @var $user User */
/* @var $domain Domain */

#Заборона прямого дуступу
defined('ACCESS') or die('Restricted access');

$user->isPermitAuth();
$user->isPermitUserStatus('admin');

$return_arr=array();

$q = $_POST["q"];
if (!$q) return;

$query="select `login` from `users` where visible=1 order by `login`";
$res=$db->query($query);
$cnt=$res->numrows();
while ($row=$res->fetchrow())
{
	
        $login=$row['login'];
	$login2 = mb_convert_case($login, MB_CASE_LOWER, "UTF-8");
	$a=(strpos($login2,$q));
	if (($a===0)) {
		$return_arr[]=$login2;		
	}
}
echo json_encode($return_arr);
exit;


?>

 


Webit.in.ua 2013