Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get query data form ajax? #14

Open
thearabbit opened this issue Aug 4, 2015 · 3 comments
Open

How to get query data form ajax? #14

thearabbit opened this issue Aug 4, 2015 · 3 comments

Comments

@thearabbit
Copy link

I use remote of select2 like this

// Server router
Picker.route('addressRemote/:term', function (params, req, res, next) {

    var items = [{id: params.term, text: params.term} // Proplem

    res.end(JSON.stringify(items));
});

// Client
 $('[name="addressId"]').select2({
        placeholder: "Search address",
        allowClear: true,
        ajax: {
            url: "/addressRemote",
            type: "GET",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {term: params};
            },
            results: function (data, page) {
                return {results: data};
            },
            cache: true
        },
        minimumInputLength: 3
    });

How to get query data form ajax on server?

@arunoda
Copy link
Member

arunoda commented Aug 5, 2015

I think you need to set the client url as /addressRemote/something

@thearabbit
Copy link
Author

Could I get by query or not?

ajax: {
..........
data: function (params) {
     return {term: params};
},

Please example.

@monbro
Copy link

monbro commented Jun 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants