What's the easiest way to assign a string returned from the server to a javascript string?
Posted
by powerboy
on Stack Overflow
See other posts from Stack Overflow
or by powerboy
Published on 2010-04-15T21:18:12Z
Indexed on
2010/04/15
21:23 UTC
Read the original article
Hit count: 132
JavaScript
|string-manipulation
The following does not work:
var js_str= '<?php echo $str_from_server; ?>';
The problem is that, $str_from_server can contain any characters. If it contains single quotes or line breaks or others, the above code will break. And I do not have access to the server-side code. What's the easiest way to "escape" the contents of $str_from_server into a javascript string, and then it can be restored later?
© Stack Overflow or respective owner