i am stuck with this for quiet sometime now. all i am trying to do is send a json text to php, process it and send a response bacl..
here is the data i am sending as my textarea value..
**asdasd #$**&**%^*( AAAA SADQWEASD /// '' \\\ '' l; "" **
below is the json sent to php (got it from console):
data={"Text":"asdasd #$&%^*( AAAA SADQWEASD /// '' \\\\\\ '' l; \"\" "}
i am using jquery ajax function as below:
function ajaxfunc(data, path){
$.ajax({
type: "POST",
url: path,
data: 'data='+data,
success: function(response){
}
});
}
in php, i am doing this.
$res = json_decode(stripslashes(escapeJsonString($_POST['feed'])), true);
function escapeJsonString($value) {
# list from www.json.org: (\b backspace, \f formfeed)
$search = array("\n", "\r", "\u", "\t", "\f", "\b", "/", '"');
$replace = array("\\n", "\\r", "\\u", "\\t", "\\f", "\\b", "\/", "\"");
$result = str_replace($search, $replace, $value);
$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
$result = str_replace($escapers, $replacements, $value);
return $result;
}
echo $res["Text"];
issue is : & .. is not getting parsed at php and hence the response is null.. i also wanted to make sure, the new line characters are detected.. basically i am expecting "WYSIWYG" using json.. json_encode and json_decode