1

I want to auto load the text box with some database values. I tried with following code but not getting the values for autocomplete. I used firebug to debug the script but neither it is showing error nor I am getting results. Here is the code-

<script src="js/jquery1.10.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script>
    $('#userlist').autocomplete({

        source: function( request, response ) {
            //alert('hi')
            $.ajax({
                url : 'ajax.php',//?action=getUsers',
                dataType: "json",
                data: {
                    name_startsWith: request.term,
                    type: 'users'
                },
                success: function( data ) {
                    //alert('in');
                    response( $.map( data, function( item ) {
                        return {
                            label: item,
                            value: item
                        }
                    }));
                }
            });
        },
        autoFocus: true,
        minLength: 0        
    });
</script>
<form action="search_result.php" name="searchform" method="post">

    <input id="userlist" type="text" class="form-control txt-auto"/>

</form>
2
  • What is the response from ajax.php? Commented Sep 23, 2014 at 15:30
  • I saw the Net tab in firebug, no request is generated. How can I debug it in good manner? Commented Sep 23, 2014 at 15:31

1 Answer 1

3

You have to wait for $('#userlist') to be created :

$(document).ready(function(){
    $('#userlist').autocomplete({
        // code ...
    });
});
Sign up to request clarification or add additional context in comments.

Comments

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.