Slashes in php variable not being parsed correctly in javascript

Possible Duplicate:
JSON: why are forward slashes escaped?

I am passing values which contain "//" from PHP to Javascript. However the values keep parsing "//" as: "//" when I decode using json, no matter how I try to enclose or escape the strings... .

Here's the code I'm using:

PHP

foreach($varr as $vr)
{
    array_push($legendarr, "%%.%% - ".$vr);                        
    array_push($linkarr, "http://".$_SERVER['HTTP_HOST']."/getdata.php?criteria=".$vr);
}

JavaScript:

pie = r.piechart(320, 240, 100, <?php echo json_encode($vcr); ?>, { legend: <?php echo json_encode($legendarr); ?>, legendpos: "west", href: <?php echo json_encode($linkarr); ?>});

The problem is that the variable linkarr is displayed in the form:

http://localhost:8090/getdata.php?criteria=......

Could anyone know why this is happening? How can I fix it?

Thanks.


A string "http://www.example.org" will still be printed as "http://www.example.org" in JavaScript.

The escaped slashes is, I believe, part of the JSON standard. But it shouldn't affect your JS code in any way.

Btw, the mysql_escape_string('//') is completely out of context; HTML != database.

链接地址: http://www.djcxy.com/p/47918.html

上一篇: JSON排除了Infinity和NaN; ECMAScript中的JSON状态?

下一篇: 斜杠在PHP变量不正确解析在JavaScript中