我一直在尝试解决这个问题,我似乎无法成功,这是我的 JS
var obj = {
method: 'feed',
link: 'http://www.myDomain.com/words/?w=<?php echo urlencode($facebookNoEscape['searchWord']) ?>',
picture: 'http://www.myDomain.com/actions/image.php?img=<?php echo urlencode($image_word) ?>&dir=thumbs',
name: '<?php echo $facebookNoEscape['word'] ?>',
caption: 'Author: <?php echo $facebookNoEscape['nickname']?>',
description: '<?php echo $facebookNoEscape['definition']?>'
};
注意:这些值可以包含 "/ 或 '/ 因为我在插入过程中允许两者,并且它们在插入过程中被 mysqli_real_escape_string 转义。
如您所见,我将来自 MySQL DB 的值回显到对象中,现在结果是这样的
SyntaxError: unterminated string literal
description: 'Well, personal favorite in the following order.
all.js (line 27, col 15)
字符串以 ' 开头
我尝试过 json_encode,并且部分有效,我没有遇到这个问题,但是,我不能使用图像链接,例如:
'http://www.myDomain.com/actions/image.php?img=<?php echo urlencode($image_word) ?>&dir=thumbs'
结果如下:
http://www.myDomain.com/actions/image.php?img="someImage"&dir=thumbs
注意“someImage”括号不应该在那里。
并且所有其他回声词都用“”括起来。
有什么建议么 ?
编辑:输出
var obj = {
method: 'feed',
link: 'http://www.funkydictionary.com/words/?w=facebook%3D1',
picture: 'http://www.funkydictionary.com/actions/image.php?img=FunkyDictionary- Facebook1-image.jpg&dir=thumbs',
name: 'Facebook',
caption: 'Author: bill',
description: 'Well, personal favorite in the following order.
1. A stalkers dream come true
2. The reason most work are never done on time.
最后一行被什么东西打断了,然后它溢出了