views:

1937

answers:

1

I am trying to use jquery autocomplete plugin, I want it to suggest ItemCodes as user types...

The problem is its not showing autocomplete box/frame/....

Just to make sure webmethod returns data on every keyup event, I assigned data to a div element, and it works as it should.

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        var strItmCodes;

        $("#txtItmCode").keyup(function() {
            var search;
            search = $("#txtItmCode").val();

            if (search.length > 0) {
                $.ajax({
                    type: "POST",
                    url: "Journal.aspx/loadData",
                    contentType: "application/json; charset=utf-8",
                    data: "{'Like':'" + $('#txtItmCode').val() + "'}",
                    dataType: "json",
                    success: function(retval) {
                        strItmCodes = retval.d.split("|");

                        $("#txtItmCode").autocomplete(strItmCodes);
                        $("#suggest").html(retval.d); //elemet 'suggest' is a div
                    }
                });
            }
        });
    });
</script>

Modified

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        //$("#txtItmCode").autocomplete({url: "Journal.aspx/loadData" });

        $("#txtItmCode").keyup(function() {
            $("#txtItmCode").autocomplete({url: "Journal.aspx/loadData" });
        });
    });
</script>
+1  A: 

I think you should enable the autocomplete plugin before the first keypress, then the plugin will add the event handlers.

Assuming you use the original autocomplete plugin:

$("#txtItmCode").autocomplete({url: "Journal.aspx/loadData"});

And make sure you service can reply to the GET request formatted by the plugin.

Thanks You for replying solsson!Yes i am using the original autocomplete pugin, I tried to enable the autocomplete plugin before the first key press.var strItmCodes;strItmCodes = "SELECT";$("#txtItmCode").autocomplete(strItmCodes);$("#txtItmCode").keyup(function(strItmCodes) {...but it still does not work.You also suggested to make sure service (Webmethod) can reply to the GET request, HOW?
Faizal Balsania
Install Firebug or LiveHTTPHeaders to see the requests sent by the autocomplete plugin
I edited the post above with correct options parameter to the autocomplete plugin.
Hello Solsson, Many Questions1) How to make backend (sql server) respond with entries separated with newline (no json or anything).2)$("#txtItmCode").autocomplete({url: "Journal.aspx/loadData"});simply does not work.
Faizal Balsania