开发者

jQuery Autocomplete JSON with JSON.NET

I must be missing something here, but I'm trying to use jQuery UI's autocomplete with an ASP.NET page method. I'm using JSON.NET to serialize the response of the method, which definitely works, and returns this:

[{"ADMIN_ID":1,"ADMIN_NAME":"SMITH"}]

...and here is my jquery code:

$("#txtName").autocomplete({
    source: function (request, response) {
        $.ajax({
            type: "POST",
            url: "MyPage.aspx/GetPerson",
            data: "{ 'q': '" + request.term + "', 'limit': '10' }",
            contentType: "application/json",
            dataFilter: function (data) { return data; },
            success: function (data) {
                var result = $.parseJSON(data.d)
                response($.map(result, function (item) {
                    return {
                        label: item.ADMIN_NAME,
                        value: item.ADMIN_ID
                    }
                }))
   开发者_如何转开发         },
            error: function (xhr, status, errorThrown) {
                alert("Error: " + xhr.responseText);
            }
        });
    },
    minLength: 1
});

Problem is, the autocomplete never shows any items. Any ideas?


Try this first, I think your response(...) code is the culprit:

$('#txtName').result(function(event, data, formatted) {
   $("#result").html( !data ? "No match!" : "Selected: " + formatted);
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜