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.