I am using Select2 jquery plugin and I can\'t get results with json. When looking json response in browser it looks ok. Like this for example:
[{
Note: just a stab at it. Just what stuck out.
Your json has no property results, so try.
$("#select2_family").select2({
minimumInputLength: 3,
ajax: {
url: "json_family.php",
dataType: 'json',
data: function (term) {
return {
term: term,
};
},
results: function (data) {
// CHANGED
return { results: data };
}
}
});
changed the query -- see if this helps
$myArray = array();
// here
if ($result = $mysqli->query("SELECT id, family AS text FROM family WHERE family LIKE '%$term%'")) {
$tempArray = array();
while($row = $result->fetch_object()) {
$tempArray = $row;
array_push($myArray, $tempArray);
}
echo json_encode($myArray);
}