Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 为什么我的.autocomplete不是';不行吗?_Jquery_Json_Cakephp_Autocomplete - Fatal编程技术网

Jquery 为什么我的.autocomplete不是';不行吗?

Jquery 为什么我的.autocomplete不是';不行吗?,jquery,json,cakephp,autocomplete,Jquery,Json,Cakephp,Autocomplete,我使用这段代码获取一个json,其中包含一个自动完成输入的区域。 json正在工作,我可以通过firebug看到它,但是autocomplete没有启动 我只想使用返回的json作为autocomplete的源代码 $(document).ready(function() { $('#AdCityId').change(function() { var city = $('#AdCityId').val(); $.ajax({ ur

我使用这段代码获取一个json,其中包含一个自动完成输入的区域。 json正在工作,我可以通过firebug看到它,但是autocomplete没有启动

我只想使用返回的json作为autocomplete的源代码

$(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
                });
            }
        });
    });
})
你应该咨询医生。做这样的事很容易

$( "#AdCityId" ).autocomplete({
      source: "http://mydomain.com/classi/ads/getDistrictsByCity?city="+$('#AdCityId').val(),
      minLength: 2,
      select: function( event, ui ) {
        //do selecting stuff here if any
      }
    });

由于AdCityID是ajax填充的$('#AdCityID')。val()为空:(