I’m making requests to my server using jQuery.post()
and my server is returning JSON objects (like { "var": "value", ... }
). However, if any of the values contains a single quote (properly escaped like \'
), jQuery fails to parse an otherwise valid JSON string. Here’s an example of what I mean (done in Chrome’s console):
data = "{ \"status\": \"success\", \"newHtml\": \"Hello \\\'x\" }";
eval("x = " + data); // { newHtml: "Hello 'x", status: "success" }
$.parseJSON(data); // Invalid JSON: { "status": "success", "newHtml": "Hello \'x" }
Is this normal? Is there no way to properly pass a single quote via JSON?
When You are sending a single quote in a query
When You get the value including a single quote
If you want to search/ insert the value which includes a single quote in a query
xxx=Replace(empid,"'","''")