0

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?

3
  • which scripting language you are using for backend? Commented Oct 5, 2012 at 5:36
  • I'm using PHP. do you have some example of this autocomplete? Commented Oct 5, 2012 at 7:45
  • Reffer this link: stackoverflow.com/questions/5305294/… Commented Oct 5, 2012 at 8:00

2 Answers 2

1

you can simply use php also

check here

this is ajax demo :)

download

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

Comments

0

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"
        });
      }
   });


});

2 Comments

correct me if I'm wrong : url: "/PublicHome/AutoPopulateLocation", //Call to Server Side >> means I have to refer to my php file like this url: "search.php" and what that search.php does is actually convert MySQL output into JSON format, is that what you mean?
and what 'search text' on this line data: "{ 'searchText': '" + request.term + "' }", refers to?

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.