0

我正在使用此代码来获取带有区域的 json 以进行自动完成输入。json 正在工作,我可以用 firebug 看到它,但自动完成功能没有触发。

我只想使用返回的 json 作为自动完成的源。

$(document).ready(function() {
    $('#AdCityId').change(function() {
        var city = $('#AdCityId').val();
        $.ajax({
            url: "http://mydomain.com/classi/ads/getDistrictsByCity",
            type: "GET",
            data: {city: city},
            dataType: "json",
            success: function(result) {
                console.log(result);
                $( "#AdDistrict" ).autocomplete({
                  source: result
                });
            }
        });
    });
})
4

1 回答 1

0

您应该查阅Jquery UI 文档。做这样的事情更容易。

$( "#AdCityId" ).autocomplete({
      source: "http://mydomain.com/classi/ads/getDistrictsByCity?city="+$('#AdCityId').val(),
      minLength: 2,
      select: function( event, ui ) {
        //do selecting stuff here if any
      }
    });
于 2013-04-20T13:15:06.430 回答