I’m using ajax function to get the data back for my jquery autocomplete but it seems to not parse the json response and I cannot find why.
I look did console.log for one that is working which is another json response and the other one which is not working and in chrome Console, I can see below. The first one is not working and second one is working.
["17","17","16","20","19","18","23","18","20","18","23","23"]
["25", "24", "25", "24", "24", "23", "21", "23", "22", "21", "22", "22"]
I can see that the second one has red color on numbers and I cannot find out why.
Can someone find out why it’s not parsing this JSON?
The second one has a space (or some other character that displays as such) after each comma. If this is how your
json_encode()call outputs it, you can run an additional measure to ensure those spaces aren’t there before returning it to your AJAX function:Don’t use that if you may have data which has spaces normally. I’m not sure if that is what is causing it to not work, but that is the only difference in the strings you showed us.
You can also use JSONLint to validate your JSON for free.