PHP jquery AutoComplete

Source: Internet
Author: User
Search on the Internet a lot, tired shi, toss a half-day, finally fix, summed up the next ...

1. Requires Jquery-1.3.2.min.js (+ +), jquery.autocomplete.js,jquery.autocomplete.css three files. Where is it? Google..

2. The front page JS is as follows:

User.js

$ (function () {$ ("#u_name"). blur (function () {///Query the user table, check for presence, presence, or display the information for users, no, just update the hidden field, identify as new//If it is a newly added user,        Save to database.        var u_name = $.trim ($ ("#u_name"). Val ()); if (u_name! = "") {$.ajax ({url: "finduser.php", type: "Get", Datatyp                    E: "JSON", data:{username:$ ("#u_name"). Val (), U: "Definate_text"}, Error:function () {                Sessiontimeout (); }, Success:function (data) {if (Data!=null) {$ ("#u_mail"). attr ("Val                        UE ", data.mail);                        $ ("#u_phone"). attr ("value", data.phone);                        $ ("#u_office"). attr ("value", data.office);                    $ ("#existflag"). attr ("value", Data.existflag);            }                }            });                }    });      Here $ ("#u_name"). AutoComplete ("finduser.php", {cachelength:0, selectfirst:true,  Matchsubset:false, Multiple:false, width:135, max:20, DataType: ' JSON ',             Extraparams: {username:function () {return $ ("#u_name"). Val ();},u: "Indefinate_text"}, Parse:function (data) {              var rows = []; if (""!=data) {for (Var i=0; I
 
  
   1))            {$ ("#u_name"). blur ();
}                    }    });}); 
  
 

3. Background PHP section:

finduser.php

 
  Query ($sql);    $autorow = $db->fetch_array ($autoresult);    $autoemail = $autorow [email];    $autooffice = $autorow [Office];    $autophone = $autorow [phone];    $existflag =1;    if ($autorow ==false) {        $existflag =0;//0 does not exist, 1 exists.    }    $array =array (' Mail ' + ' $autoemail ', ' office ' = ' + ' $autooffice ', ' phone ' = ' $autophone ', ' Existflag ' and ' $ Existflag ");    echo Json_encode ($array);} if ($flag = = ' Indefinate_text ') {    $sql = "Select user_name from $users _table where user_name like '". $_get[' username '] ." %'";    $autoresult = $db->query ($sql); $db is to create a good mysql_connect,query method is actually called mysql_query    $array =array ();    while ($row = $db->fetch_array ($autoresult)) {        Array_push ($array, Array ($row [' user_name ']));    }    echo Json_encode ($array);}? >

4. Front page on an input box, the main is the above PHP return and JS processing.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.