Home  >  Article  >  Backend Development  >  jquery+php queries mysql to implement automatic completion function_PHP tutorial

jquery+php queries mysql to implement automatic completion function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:54:20861browse

About jquery+php query mysql to implement the auto-complete function, I wrote this tutorial because most of the auto-complete applications I have seen just give you a program source code package and then tell you how to use it. Not telling you how it works and why it does it. And knowing this allows you to further customize this plug-in to your own needs (I have written many articles about other applications in my blog about this).

Okay, let’s get started now.

JavaScript code :

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com]

Explanation of JS:

Okay, as you can see from the above code, we need to connect to a file called rpc.php, which handles all operations.

The lookup function uses the word obtained from the text input box and then passes it to rpc.php using the Ajax method POST in jQuery.

If the input character 'inputString' is '0' (Zero, translator's annotation: here refers to no input in the search box), the suggestion box will be hidden. This is also very user-friendly. If you want to search, Nothing is entered in the box, and you don't expect a suggestion box to appear.

If there is content in the input box, we get the ‘inputString’ and pass it to the rpc.php page, and then jQuery’s .post() function is used, as follows:

.post(url, [data], [callback])

The 'callback' part can be associated with a function. This is more interesting. It will only be executed when the data is loaded successfully (Annotation: This is a free translation, I did not understand the original text: <).

If the returned data is not empty (that is, there is something to display), then display the search prompt box and use the returned data to replace the html code in it.

It’s that simple!

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364623.htmlTechArticleAbout jquery+php query mysql to realize the automatic completion function, I wrote this tutorial because most of the things I have seen about automatic The completed application just gives you a program source code package, and then reports...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn