-2
jQuery(function() {
    var autosuggestions = [
        "Airport",
        "Restaurant",
        "Shop",
        "Entertainment",
        "Realestate",
        "Sports",
        "Cars",
        "Education",
        "Garden",
        "Mechanic",
        "Offices",
        "Advertising",
        "Industry",
        "Postal",
        "Libraries"
    ];
    jQuery('#search-what').autocomplete({
        source: autosuggestions
    });
});

Please help me to write Ajax AutoSearch Code fetching data from Database and not using var autosuggestions.

4
  • explain your requirement briefly Commented Aug 24, 2014 at 10:27
  • Take a look here, it has many examples of autocomplete jqueryui.com/autocomplete. Check the "Remote datasource" one. Commented Aug 24, 2014 at 10:28
  • In the above code, Data is fetched from pre-defined data using array var suggestions. But I want data should be drawn from database. Commented Aug 24, 2014 at 10:28
  • @TasosK.I have checked the above example. There, the data is shown in another div with div id log, But I want to show it in the same inputbox on autoselection. Commented Aug 24, 2014 at 10:40

1 Answer 1

0

if you mean the way that Google is doing search we call it search suggest or autocomplate.

there are a lot of way to do this but if you are begginer or don't have time and finding a good and fast way for this try jquery UI autocomplate

That is so easy:

Your script:

     <script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>

and HTML

  <div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>

and after you working with this and if you know how to work with autocomplate then start to fetching data from database, there is a good tutorial here and HERE

Sign up to request clarification or add additional context in comments.

4 Comments

I am already using a script for autosearch, but need to add autosearch feature, fetching data from database in the above code that you have mentioned.
Please help, I am a beginner in this.. Need your support. What would be the server side code for this.
@AwdeshBhatti please first check this answer for the your selected answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.