开发者

Show JSON with jquery

开发者 https://www.devze.com 2022-12-21 22:37 出处:网络
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.\"</s

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'])?

0

精彩评论

暂无评论...
验证码 换一张
取 消