JSON formatting
- New lines aren't parse by jQuery function $.parseJSON(). To correct this replace the printed string at the back-end:
- Don't use addslashes()
- Back-end
$strVar=preg_replace("/(\n|\r)/",'\n',$strVar);
echo '"placeholder_id:"'.$strVar.'"';exit;
- Front-end
$.post("http://www.your-url.com",{ "param": "param-value"},function(data)
{
var obj = $.parseJSON(data);
if(obj)
{
$('#placeholder_dom_element').html(obj.placeholder_id);
}
}