jquery Autocomplete working with older versions of the browsers but not new ones? jquery Autocomplete working with older versions of the browsers but not new ones? php php

jquery Autocomplete working with older versions of the browsers but not new ones?


The error message means you have control characters in your JSON response (something like \n, \t, etc). Newlines and the other control characters are not allowed in JSON strings, according to ECMA262 5ed. You can fix it rather easily by escaping or removing those characters, either from PHP or from Javascript.

Here you can find an example of how you can fix it from PHP, as the problem most likely comes from json_encode (which I assume you're using): http://codepad.org/Qu7uPt0EAs you can see, json_encode doesn't escape the \n so you have to do it manually before outputting.

Now for the mistery related to older browsers. If you look at jQuery's parseJSON function you'll notice that it first tries to parse the string with the browser's builtin JSON object and if it doesn't find any, it will just do a (sort of) eval (which will work even with newlines). So it probably works for you on Firefox < 3.5 or IE < 8 which don't have a native JSON object.Also, it probably works with other search terms (like as, etc) simply because they don't include a result which has control characters.


Adding to draevors correct answer.

Look at downloading the JSON2 libraryhttps://github.com/douglascrockford/JSON-jsThat is how i got around this problem