I'm using jquery Select2 4.1.0-rc.0 This is my Javascitp code:
$('#task_dname').select2({
placeholder: 'Select an item',
// tags: true,
// cache: true,
delay: 250,
maximumInputLength: 20,
minimumInputLength: 2,
dataType: 'json',
ajax: {
type: 'post',
url: 'query_list_tasks.php',
data: function (params) {var post_data = {searching: params.term, query: 'task_list'}; return post_data;},
processResults: function (data) {
console.log(data);
return {
results: data.items
};
}
}
});;
PHP generating json:
while ($row = $result->fetch_assoc()) {
$response[] = array(
"id" => $row['id'],
"text" => $row['text']
);
}
//echo json_encode($response);
echo '{ "results": '.json_encode($response).'}';
Json for processResults data (console.log):
{ "results": [{"id":"10","text":"Test1"},{"id":"11","text":"Test2"}]}
This seems ok but i get this error when i try to search something, and there is no options in select field showing up:
jquery.min.js:2 jQuery.Deferred exception: Cannot read properties of undefined (reading 'slice') TypeError: Cannot read properties of undefined (reading 'slice')
Something is missing or im just to stupid? I'm. stuck.