First, I’m sending an entire json object, full of data. Following, is only an example of a string data that doesn’t get converted properly.
starting from this string:
"Verticale dall'alto verso il basso, Verticale dal basso verso l'alto"
When sending it with jquery ajax (json), it becomes like this:
"Verticale dall'alto verso il basso, Verticale dal basso verso l'alto"
This is the sending code:
$.ajax({
url: ajax_url
,type: 'post'
,dataType:'JSON'
,data: data
Obviously, I don’t want to get escaped single quotes. On my database I want to write “‘”, not “‘”.
How to?
2
Answers
Thanks to @Jintor, the solution was the following:
In my program, data comes to me from other sources in plain json format, then I have to add some other fields to it, and finally pass it to
$.ajax
. At that point, what I'm doing is to stringify the original object, replace all the straight quotes, than parse it to JSON again and pass it to ajax.Probably I should also take care of double quotes, but anyway, this is my current solution.
you could be smart and use a .replace all quotes to apostrophe
OR
You could try
var json = encodeURIComponent(string)