0

I am using select2 plugin and mongodb for my project. Chrome does work well; however, firefox doesn't, when I am trying to construct an option with value (id) as ObjectsId (string), it fails with an error.

JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 10 of the JSON data

When instead of ObjectId I use number (integer), Firefox does work well.

Server response for a plugin - http://jsfiddle.net/p41jydsd/

<input autocomplete_
    url="/tag/autocomplete/"
   class="form-control select2-widget"
   id="_tags" 
   inline_create="true"
   multi="true"
   name="tags"
   type="hidden" 
   value="[{&quot;text&quot;: &quot; \u041c\u043e\u0441\u0433\u043e\u0440\u0438\u0437\u0431\u0438\u0440\u043a\u043e\u043c&quot;, &quot;id&quot;: &quot;544e67760faabf52c77c0dd2&quot;}]" />

Thanks in advance.

alexvassel
  • 10,600
  • 2
  • 29
  • 31
  • Please provide your code or jsfiddle and i think there is some namespace conflict. – Innovation Jan 20 '15 at 07:52
  • The suspicion here would be that this is a limitation of the plugin where it expects the "id" value to be numeric. Test with alphas "a", "b", "c" etc, to see if the same thing results. Else, are you sure the "ObjectId" is just a "string", or is it in fact `{ "_id": { "$oid": "54be099f60c191cf9edd7235" } }`? Depends on your language and library on the server side. – Neil Lunn Jan 20 '15 at 07:55
  • @NeilLunn single character doesn't work; it is a string and the whole thing does work in Chrome. – alexvassel Jan 20 '15 at 08:00
  • Understand that it was a "lexical" test to see if any "char" type was a problem. Seems a bit odd considering that the content should be an array though. Smells like a bug, but probably needs some inspection to see the root cause. Complete example with embedded data in a var should suffice, and is preferred to a "fiddle" here really. You can always do "both" for the lazy :) – Neil Lunn Jan 20 '15 at 08:03
  • @NeilLunn here what get's a plugin from a server - http://jsfiddle.net/p41jydsd/ – alexvassel Jan 20 '15 at 08:17
  • Well I think there is some "code" associated with that to make it complete. Not sure why you are putting this content into the HTML as an encoded string. But suspect that's part of the problem. Please follow the model and include the content in your question rather than just a link to a fiddle. Linked content changes or goes away over time. That's why we ask to keep it complete here :) – Neil Lunn Jan 20 '15 at 08:43
  • thanks, guys, the answer was here - http://stackoverflow.com/questions/1479233/why-doesnt-firefox-show-the-correct-default-select-option – alexvassel Jan 20 '15 at 11:16

0 Answers0