-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Allow custom "remote" for bloodhound. #907
Comments
Hi Kevin. I was needing this too; I had a dig around in the source and found a possible extension point. This might be intended and is just undocumented; or they will implement something else in the future. What you do is implement your own transport callback in the bloodhound remote options, then fire the error or success functions passed in by Bloodhound so that it can continue with the response. In my example, I've just implemented what the default transport does (call Jquery ajax). var test = new Bloodhound({
remote: {
transport: function (url, options, onSuccess, onError) {
// Here, maybe log that we're about to look up remote data.
// Here's where you'd do your custom lookup; for this example, we'll just use Jquery ajax as Bloodhound does.
$.ajax(url, options).done(done).fail(fail).always(always);
function done(data, textStatus, request) {
// Don't forget to fire the callback for Bloodhound
onSuccess(data);
}
function fail(request, textStatus, errorThrown) {
// Don't forget the error callback for Bloodhound
onError(errorThrown);
}
function always() {
}
}
}
}); |
I've actually gone ahead and updated the Bloodhound API docs with the above, and put in a pull request: #921 |
Thanks @DavidMoore that is exactly what I am looking for. |
Currently Bloodhound forces request to be made with
jQuery.ajax
. It would be nice if alternative "fetchers" could be plugged in.The advantage would be flexibility and the options to get results from other places such as arbitrary javascript api's or non-json endpoints.
Concept API:
The text was updated successfully, but these errors were encountered: