Saint Robson
Saint Robson

Reputation: 5525

jQuery Autocomplete From MySQL Result (No JSON - If Possible)

I need to have autocomplete feature on my website, but I'm not JSON-guy. I never dealing with JSON so I hope I still can have autocomplete from plain MySQL result.

but from what I saw here : http://jqueryui.com/demos/autocomplete/ I don't see any possibilities to get autocomplete from MySQL result. is it true?

Upvotes: 0

Views: 948

Answers (2)

M.I.T.
M.I.T.

Reputation: 1042

you can simply use php also

check here

this is ajax demo :)

download

Upvotes: 1

G . R
G . R

Reputation: 541

You just need to make an AJAX call and take the search results then send them back as JSON to the client side.Then just bind it with the AutoComplete Textbox.

The jQuery plgin to be used is http://docs.jquery.com/UI/API/1.8/Autocomplete

Example- A textbox with ID 'txtlocation' is added with autocomplete functionality here.
$(document).ready(function(){

   $("#txtlocation").autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "/PublicHome/AutoPopulateLocation", //Call to Server Side 
            data: "{ 'searchText': '" + request.term + "' }",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataFilter: function (data) { return data; },
            success: function (data) {
                    response($.map(data, function (item) {
                        return {
                            value: item.Suburb 

                    }))
                },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

            }
        });
    },
    open: function (event, ui) {
        $(this).autocomplete("widget").css({
            "width": 344,
            "font-size": 11,
            "font-family": "Arial"
        });
      }
   });


});

Upvotes: 0

Related Questions