最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to append params to ajax request in Select2? - Stack Overflow

programmeradmin0浏览0评论

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 ?

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 ?

Share Improve this question asked Nov 3, 2014 at 13:49 Iliyass HamzaIliyass Hamza 1,4053 gold badges17 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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;
        },
        ...
    }
});
发布评论

评论列表(0)

  1. 暂无评论