带有附加参数的jQuery自动完成

时间:2017-02-12 19:08:59

标签: php jquery ajax autocomplete


我正在执行自动完成功能并且我传递参数,但它不起作用。

$("#destination-region").autocomplete({
    source: "/interface/regions_datalist.php?idCountry="+$("#destination-country-id").val(),
    minLength: 2,
    select:
        function (event, ui) {
            $("#destination-region-id").val(ui.item.idRegion);
                $("#destination-country-preview")
                    .html('<i class="fa fa-map-pin" aria-hidden="true"></i> ' + $("#destination-country").val() + " - " + $("#destination-region").val());
        }
});

这是我的PHP代码(我已尝试使用此链接:www.site.ext / interface / regions_datalist.php?idCountry = 1&amp; term = la)并且它有效!

<?php
include_once "../core/adminAutoloader.php";

$idCountry = $_GET["idCountry"];
$name = $_GET["term"];
$regionFacade = new regionFacade();
$regions = $regionFacade->findRegionByNameAndCountry($idCountry,$name);
$regionsArray = array();
while($region = $regions->fetch(PDO::FETCH_ASSOC)) {
    $tmpRegion["idRegion"] = $region["idRegion"];
    $tmpRegion["value"] = $region["name"];
    $tmpRegion["label"] = $region["name"];
    array_push($regionsArray,$tmpRegion);
}
echo json_encode($regionsArray);
你能帮助我吗? 我已经在stackoverflow上阅读了很多问题,但是没有人帮助过我! 谢谢!

0 个答案:

没有答案