php:5.3.3
jquery:1.7.2
here is the way we use to send the value from php to jquery.
- get the escaped string.
$a = '"xxxxx'; $b = json_encode($a);
and now, $b is '"xxxxx';
-
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'>""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.