jquery+php query MySQL implementation of automatic completion function

Source: Internet
Author: User

<script src= "jquery-1.2.1.pack. Web Effects" type= "text/Web Effects" ></script>
<script type= "Text/javascript" >

function Lookup (inputstring) {
if (Inputstring.length = = 0) {
Hide the suggestion box.
(' #suggestions '). Hide ();
} else {
. Post ("rpc.php", {querystring: "" +inputstring+ "}, function (data) {
if (Data.length >0) {
(' #suggestions '). Show ();
(' #autosuggestionslist '). HTML (data);
}
});
}
}//Lookup

function Fill (thisvalue) {
(' #inputstring '). Val (Thisvalue);
(' #suggestions '). Hide ();
}

</script>

jquery+php query MySQL to implement AutoComplete, write this tutorial, because most of the things you've seen about AutoComplete are just giving you a source code package, and then telling you how to use it, rather than telling you how it works and why. Knowing this will allow you to further customize the plugin to your own needs (I've written a lot about other apps in my blog about this).

Method Two

Json

$ (function () {
var text = $ (". Input"). Text ();
settimeout (function () {
if ($ (". Input"). Text ()!= text)
{
Text = $ (". Input"). Text ();
$.ajax ({
Type: "Get",
URL: "xxxx",//Put your PHP URL
Data:{text:text},//The data you accept in PHP is named text
DataType: "JSON",//Pass back time in JSON mode
Error:function ()
{
Alert ("Ajax load Failed");
},
Success:function (JSON)
{//json for returned data, do data binding here
var ottery = Json.data;
var $xiala = $ (' <div class= "Xiala><ul id=" datas "><li id=" Row "><li></ul></div>); ><li id= "Row" ><li> is a template for storing data
for (Var i=1;i<ottery.length;i++)
{
var row = $ ("#row"). Clone ();
Row.html (OTTERY[I].SSSJ);
ROW.ATTR ("id", "Ready");//change the ID of the row that binds the data
Row.appendto ("#datas");//Add to Template's container
}
$ ("#row"). Hide ();
$xiala. Appendto ("body");
})
}
},10);
})

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.