David Undy
David Undy

Reputation: 953

Database Search - Single AJAX Query + Javascript Filter

I've been looking at different ways to implement an instant text search on my web application; at the moment it uses a very basic SQL LIKE query with wildcards.

I have looked at many ways to implement searches, but I never saw anyone suggest to do the following:

  1. As the user types, when the query gets to 4 or 5 characters, perform the database search.

  2. Display the results to the user, and as they continue typing, just use Javascript to filter the results, so no more database calls are required.

This way there would only ever be one database call per search, if the user makes a typo, they can backspace and Javascript would take care of displaying the correct results.

Are there any downsides to this method?

Upvotes: 2

Views: 474

Answers (1)

Scott Yang
Scott Yang

Reputation: 2428

This seems to work in theory, but I personally prefer either pressing enter or waiting 500 milliseconds of inactivity before searching.

One thing that may cause an extra DB query is if the user backspaces at your given interval (4 characters in your case).

But I suppose the real downside would be extra JS coding + still needing the PHP coding.

Upvotes: 1

Related Questions