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

Add support for a custom remotePreprocessor function & autodetect JSONP #29

Closed
wants to merge 2 commits into from

Conversation

dogoku
Copy link

@dogoku dogoku commented Feb 22, 2013

Solves #8

Adds remotePreprocessor option to the Dataset specifications, which can process the response of a remote server call, in case the response is not in the correct format.

The function takes the response as a parameter and returns an array of
strings or canonical datums. See Datums for more information

Also compares window.location with the remote url to determine whether JSONP is required for a successful request and sets the appropriate dataType for the $.ajax

Updated the test suite & Readme.md

Adds remotesPreprocessor function which can process the response of a
remote server call, in case the response is not in the correct format.

The function takes the response as parameter and returns an array of
strings or canonical datums. See
https://github.com/twitter/typeahead.js#datums for more information
Compares the current location with the remote url to determine whether
JSONP is required to communicate and sets the appropriate dataType for
the $.ajax request
//IE does not support location.origin, therefore we build it manuaully
var origin = [location.protocol,'//',location.host].join('');

return new RegExp(origin).test(url) ? 'json' : 'jsonp';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't allow CORS

@jharding
Copy link
Contributor

Appreciate the pull request, but this overlaps with #25. If you have time, look over that pull request and post any feedback you may have.

@jharding jharding closed this Feb 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants