jquery+php query MySQL to implement auto-complete function _php Tutorial

Source: Internet
Author: User
About jquery+php query MySQL implementation autocomplete feature, write this tutorial, because most of the applications you've seen about auto-completion just give you a program source package and then tell you how to use it instead of telling you how it works and why. Knowing this will allow you to further customize the plugin to your needs (I have written a lot of articles about other applications in my blog).

OK, let's start now.

JavaScript code :

Copy to ClipboardWhat to refer to: [www.bkjia.com]

JS's explanation:

Well, from the code above, we need to connect to a file called rpc.php, which handles all operations.

The lookup function uses the word from the text input box and then uses the Ajax method post in jquery to pass it to rpc.php.

If the input character ' inputstring ' is ' 0 ' (Zero, that is, it is not entered in the search box), the suggestion box is hidden, which is also very human, you think, if you do not enter anything in the search box, you do not expect to appear a suggestion prompt box.

If there is content in the input box, we get the ' inputstring ' and pass it to the rpc.php page, and then the jquery. Post () function is used, as follows:

. Post (URL, [data], [callback])

The ' callback ' section can be associated with a function, which is interesting only when the data is loaded successfully (this is a free translation, not read the original:<).

If the returned data is not empty (that is, there is something to display), then a search prompt is displayed and the returned data is used instead of the HTML code.

It's so easy!

    • Total 4 Pages:
    • Previous page
    • 1
    • 2
    • 3
    • 4
    • Next page

http://www.bkjia.com/PHPjc/364623.html www.bkjia.com true http://www.bkjia.com/PHPjc/364623.html techarticle about jquery+php query MySQL implementation auto-completion function, write this tutorial, because most of the auto-completed applications have just given you a program source package, and then Sue ...

  • Related Article

    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.