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

remote not working without filtered response #1656

Open
jektvik opened this issue Jul 12, 2017 · 1 comment
Open

remote not working without filtered response #1656

jektvik opened this issue Jul 12, 2017 · 1 comment

Comments

@jektvik
Copy link

jektvik commented Jul 12, 2017

The below code will not work if the server doesn't filter responses based on the QUERY. If remote is replaced by prefetch, it will work fine.

`var customers = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/customers?query=%QUERY',
wildcard: '%QUERY'
}
});

        $('#customer').typeahead({
            minLength: 3,
            highlight: true
        }, {
            name: 'customers',
            display: 'name',
            source: customers
        })`

The AJAX request is sent and received properly for example like below:

[
{
"id": 4,
"name": "Arnie Sch",
"isSubscribedToNewsletter": true,
"membershipTypeId": 1,
"membershipType": {
"id": 1,
"name": "first"
},
"birthdate": null
},
{
"id": 5,
"name": "Sly Stallone",
"isSubscribedToNewsletter": true,
"membershipTypeId": 1,
"membershipType": {
"id": 1,
"name": "first"
},
"birthdate": null
},
{
"id": 6,
"name": "Hugo Weaving",
"isSubscribedToNewsletter": true,
"membershipTypeId": 1,
"membershipType": {
"id": 1,
"name": "first"
},
"birthdate": null
},
{
"id": 7,
"name": "Natalie Portman",
"isSubscribedToNewsletter": true,
"membershipTypeId": 2,
"membershipType": {
"id": 2,
"name": "second"
},
"birthdate": "1995-05-05T00:00:00"
},
{
"id": 9,
"name": "Jason Statham",
"isSubscribedToNewsletter": true,
"membershipTypeId": 2,
"membershipType": {
"id": 2,
"name": "second"
},
"birthdate": "2000-01-01T00:00:00"
}
]

But the script does not yield any suggestions:
image

However, as stipulated in the first paragraph, if the server controller is modified to return only responses based on the sent query(wildcard) the suggestions appear as they are meant to.

@dhaneshRaj
Copy link

dhaneshRaj commented Jul 14, 2017

{
"id": 4,
"name": "Arnie Sch",
"isSubscribedToNewsletter": true,
"membershipTypeId": 1,
"membershipType": {
"id": 1,
"name": "first"
},
"birthdate": null
}

remove inside suggestions.js [] its works me, even i m searching some MIME issue..
HTML should be this

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src='http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js'></script> <script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>

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

No branches or pull requests

2 participants