开发者

jQuery .autosuggest retains results

my jquery autocomplete plugin retains the results of an initial search and does not replace these with the results of a new search. My ASP code is as follows:

<body>
<form id="form1" runat="server">
  <asp:TextBox ID="txtSearch" class="controls_icr_searchbox" runat="server" 
                    style="width:200px;"/>
</form>
</body>

While the jQuery that makes the Ajax call looks like this:

$(document).ready(function () {    
        $('.controls_icr_searchbox').keyup(function () {
            if ($('.controls_icr_searchbox').val().length > 4) {
                //Code to fetch
开发者_如何学编程                //var divToBeWorkedOn = '#AjaxPlaceHolder';
                var parameters = "{'query':'" + 
                                    $('.controls_icr_searchbox').val() + "'}";
                var url = 'AutoComplete.asmx/GetAddress';
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: "json",
                    data: parameters,
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        var datafromServer = data.d.split(":");
                        $("[class$='controls_icr_searchbox']").autocomplete({
                            source: datafromServer
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            }
          });    
    });

The ajax call returns the results fine each time but they don't appear to be bound on the .autocomplete event.


I have found the cause of my problem. After successfully pulling back the results of the Ajax Query I tried to assign them to the autocomplete using the following code:

$("[class$='controls_icr_searchbox']").autocomplete({

Strangely this worked on the first instance but failed on any subsequent changes. My code now works correctly using the following code in place of the above:

$(".controls_icr_searchbox").autocomplete({
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜