Solved it. The json must return [{"id": "value", "text":"value"}] format.
Apr 10, 2015
11
Level 1
Select2 ajax on Laravel
Hi, has anyone successfully integrated Select2 on Laravel5 ? This is with ajax. I almost got it to work, the only problem I am having right now is on the part of processing results. This is the json output:
[
{
"id": "43affe22-df76-11e4-b2e5-00e040016184",
"name": "beer"
},
{
"id": "ec6339da-df76-11e4-83d3-00e040016184",
"name": "Beers"
}
]
And this is my js script:
$('#tag_list').select2({
placeholder: 'Enter a tag',
ajax: {
dataType: 'json',
url: '{{ url("api/tags") }}',
delay: 400,
data: function(params) {
return {
term: params.term
}
},
processResults: function (data, page) {
return {
results: data
};
},
}
});
Or is it my json that is wrong?
Level 1
3 likes
Please or to participate in this conversation.