My problem is html content not being parsed with JSON.parse .
-
I am getting input from a content editable div.
var content = $("#contentInput").html(); -
I am sending it to server after
JSON.stringifyvar dataToServer= JSON.stringify(content); //sending an object -
The same content I am getting from server, and I attempting to parse it.;
var dataFromServer = JSON.parse(content);
Here my problem raises parser throwing error. content of html data receiving as it is.
I was tried eval but after reading the some articles I was withdrawn my decision.
How to resolve the problem.
Here is fiidle demo of working code.
The problem is your server corrupting the content. Please check out your server code, it may add some non printable charaecters.
JSON.parse fails if the content not in JSON format. It strictly follow the rules of jsonstring to parse it( I mean double quotations and other /).
Your server may be adding some other unuseful characters to content or jsonstring.