I have following PHP code
$val="<div id=user".$row['cid']." userid=".$row['cid']." class=innertxt><img src=images/images.jpg width=50 height=50><strong>".$uname."</strong><ul> <li>Email: ".$row['cemail']."</li> <li> <input type=checkbox id=select".$row['cid']." value=".$row['cid']." class=selectit /></li> </ul> </div>" ;
$return["foo"] =$val;
print json_encode($return);
but once i get result i get in following format ?
<div id=user11 userid=11 class=innertxt>
<img src=images\/images.jpg width=50 height=50>
<strong>Ruby<\/strong>
<ul>
<li>Email: ruby@qualityhouse.ae<\/li>
<li> <input type=checkbox id=select11 value=11 class=selectit \/><\/li>
<开发者_运维技巧\/ul>
<\/div>
why i am getting this / and how to solve it?
The stripslashes
method can be used. Checkout the following snippet:
print stripslashes(json_encode($return));
more details can be found at the php documentation
Slashes should be escaped with a backslash, so the output is correct.
Try this:
var x = eval({ var: "<\/div>" });
alert(x.var);
It will produce the correct output. (</div>
)
The interesting thing is, that you got a string, instead of an object. Are you sure that the code fragment is correct? Because it shoud be:
{ foo: <div id=user11 userid=11 class=innertxt><img src=images\/images.jpg width=50 height=50><strong>Ruby<\/strong><ul> <li>Email: ruby@qualityhouse.ae<\/li> <li> <input type=checkbox id=select11 value=11 class=selectit \/><\/li> <\/ul>
<\/div> }
Are you sure you wrote json_encode($return)
, instead of json_encode($return['foo'])
?
精彩评论