Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append params to ajax request in Select2?

i'm building a web app using Laravel, and i have to implement tag selection, like this one used by stackoverflow, loading options via ajax and if is not exist create it, i did choose Select2 jquery plugin, the problem i have with it, is cant get it to append parameters to the ajax url,

Route :

 /tags/{tag}

how can i append the term of select to my url ?

like image 875
Iliyass Hamza Avatar asked Mar 18 '23 00:03

Iliyass Hamza


1 Answers

In Select2 3.x, you can pass a function as the ajax.url option. It will be passed the current search term as the first parameter, which sounds like what you are looking for.

$element.select2({
   ...
    ajax: {
        url: function (term) {
            return '/tags/' + term;
        },
        ...
    }
});
like image 150
Kevin Brown-Silva Avatar answered Mar 26 '23 02:03

Kevin Brown-Silva