0


I'm doing an autocomplete function and I'm passing parameters, but it doesn't work.

$("#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());
        }
});

This is my php code (i've tried it with this link: www.site.ext/interface/regions_datalist.php?idCountry=1&term=la) and it works!

<?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);

Can you help me?
I've already read a lot of question here on stackoverflow, but noone has helped me!
Thank you!

ProtoTyPus
  • 1,272
  • 3
  • 19
  • 40
  • It doesn't work __how exactly__? Any errors in developers console? – u_mulder Feb 12 '17 at 19:11
  • You need to transform the object you are getting back into an array in the format that jQueryUI expects. http://stackoverflow.com/questions/11435433/jquery-ui-autocomplete-with-json – bxN5 Feb 12 '17 at 19:54
  • @Roman I do what u say. Infact the same script wiithout extra parameter works! – ProtoTyPus Feb 12 '17 at 19:58
  • so if you pass just ww.site.ext/interface/regions_datalist.php it's works fine? Can you var_dump regions_array before json_encode with and without parameters? – bxN5 Feb 12 '17 at 22:22

0 Answers0