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!