This type of problem is sometimes difficult to debug, because so many components relate to your data, and each of them needs its own citation or escaping style to make sure that your data passes as you wish.
The first thing to do is make sure that the data gets into the ajax function correctly. Before the ajax function, use console.log or alert() to see how the data looks. Depending on where the data is coming from, it may not even be right at this point.
You can use the Firebug Net panel to see what request was actually made to the server to see the data coming out of the browser. If you have access to the server, you can debug inside the ajax function handler to find out what data it received.
Basically, you need to go all the way where the data starts from, where the data is incorrect, and find the point at which it made the wrong turn.
source share