Skip to content Skip to sidebar Skip to footer

Remove Slashes Jquery From Json

I send data via ajax so: $res = array(); foreach($series as $i){ //print_r($i); array_push($res, $i); } //print_r ($res); print (json_encode($res, JSON_UNESCAPED_SLASHES));

Solution 1:

Your PHP code returning JSON in to String not in Object

Use JSON.parse instead of JSON.stringify()

Replace success function like this:

success: function(json){
alert(JSON.parse(json));
//json = json.replace("\\", " ");alert(json);
console.log(json);

Solution 2:

json.stringify returns the data as string.so you need to parse it to get in array format which will remove slashes automatically.

vardata = JSON.parse(json);

alert(data);
console.log(data);

Solution 3:

First of all you have to parse your string and after that you can use json.replace

var obj = jQuery.parseJSON( '{ "name": "John\\" }' );
var myname=obj.name ;
myname.replace("|","");

Post a Comment for "Remove Slashes Jquery From Json"