2

I am making an application that is purely out of JavaScript (frontend and backend). So now I am using jQuery.tokenInput.js and I am having some troubles with the plugin recognizing the script.

First of all, it's not logging any error messages so I don't even know if it's an issue on my end or not.

I've essentially created a route in the application /autocomplete/tags and it accepts q parameter as well.

So when I type in something like this /autocomplete/tags?q=r I get the following result on the page

[{"tag_name":"Android","_id":"ooJaBpZ6MShmzbshY"},{"tag_name":"RPG","_id":"KpvAqCRqKKP5rbGLD"}]

So now when I initialize the plugin like this

$('#tag_input').tokenInput("/autocomplete/tags", {
            theme: "facebook",
            propertyToSearch: "tag_name",
            tokenLimit: 5
        });

It changes the input and everything. I've even tried with constant data and it seems to work but not with a script for some reason.

Is there a way I can debug/troubleshoot? Can I somehow turn on logging for this plugin? I don't actually see any issue with the way that I am doing it. I've looked at the demos and they return JSON in exactly the same way.

If you've got any ideas, it would be great!

user1952811
  • 2,398
  • 6
  • 29
  • 49
  • Ensure your script is returning the correct JSON header type with your data. When you say it seems to work with constant data - do you mean the exact same data set? Not having an `id` field has been known to cause problems: http://stackoverflow.com/questions/20516387/jquery-tokeninput-first-search-doesnt-work – Chris May 12 '14 at 08:46
  • without id, it'll just have an "undefined" id when returning the objects. It's not too big of a problem. I'll take a look at the JSON header. – user1952811 May 12 '14 at 13:55
  • Oh, so you are getting something? Can you clarify what is, and isn't working at the moment? – Chris May 12 '14 at 13:57
  • Also, are you running your JS on the same machine as the serving page? If it's cross domain, that will prevent it working. – Chris May 12 '14 at 13:58
  • That was for when I have static data. So in static data, the structure is exactly the same. When I check for objects it just has id as undefined, that's all. @Chris when running the script, essentially nothing is working. It just endlessly searches. I am also running JS on the same machine / same domain. – user1952811 May 12 '14 at 14:03
  • Ok. I'd check with Chrome Webtools or something for the returned AJAX, that it's returning valid JSON, and with the right headertype. Do you get a Javascript error thrown at any point? (The plug-in doesn't have build in logging.) – Chris May 12 '14 at 14:07
  • 1
    No errors, I'll be checking for the returned header type when I get home. I'm currently at work. Thanks for all the help :) – user1952811 May 12 '14 at 14:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52526/discussion-between-chris-and-user1952811) – Chris May 12 '14 at 14:08

1 Answers1

1

The JSON returned from an external service must be returned under an application/json header type - we found that this service was returning text/html instead.

Information about how to specify the content type with Meteor can be found on this question.

Community
  • 1
  • 1
Chris
  • 5,882
  • 2
  • 32
  • 57
  • Take a look at this for further information on how to set up the script on Meteor: http://stackoverflow.com/questions/23643723/specifying-content-type-in-meteor-javascript/23666992?noredirect=1#23666992 – user1952811 May 15 '14 at 14:15