doujiao0110 2013-03-31 12:47
浏览 12

如果json_encode一个字符串包含(&)在phtml中,浏览器将改变它的构造,如何防止它?

php:5.3.3

jquery:1.7.2

here is the way we use to send the value from php to jquery.

  1. get the escaped string.

$a = '"xxxxx'; $b = json_encode($a);

  1. and now, $b is '"xxxxx';

  2. put $a in phtml.

    php: $this->view->b = $b;

    phtml: <div id='my_data' style='display:none;'><?php echo $this->b;?></div>

so in the phtml, the string is

<div id='my_data' style='display:none'>"&quot;xxxxx"</div>

but, when the the string show in browser, it will become ""xxxxx"。And when we use $.parseJSON($("#my_data").text());. JQuery will throw an exception, because ""xxxxx" is not a JSON string.

so, how to resole this ?

or any other ways to send an escaped string from php to JQuery.

thank u all.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 蓝桥oj3931,请问我错在哪里
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染