doukang7486 2013-05-28 16:09
浏览 34

javascript的问题,发布到facebook API,通过<php echo?>,需要转义'和'

ive been trying to fix this for a few houers, i cannot seem to do it successfully, here is my 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']?>'
};

NOTE: the values can contain "/ or '/ since i allow both in the insertion process, and they get escaped by mysqli_real_escape_string in the insertion process.

As you see, i echo the values which are from my MySQL DB, in to the object, now the result is this

SyntaxError: unterminated string literal
description: 'Well, personal favorite in the following order.
all.js (line 27, col 15)

the string starts with a '

I have tried to json_encode, and that partialy works, i dont encunter the issue, but, i cannot use image links like:

'http://www.myDomain.com/actions/image.php?img=<?php echo urlencode($image_word) ?>&dir=thumbs'

which results in something like:

http://www.myDomain.com/actions/image.php?img="someImage"&dir=thumbs

notice the "someImage" brackets are not supposed to be there.

And all other echoed words are enclosed by "".

Any suggestions ?

EDIT: The output

 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. 

last line is broken with something, and then it flows over

  • 写回答

2条回答 默认 最新

  • dppb79372 2013-05-28 16:15
    关注

    If there are single quotes in what you're echoing, it will break your javascript. You'll need to use addslashes to escape your quotes:

    description: '<?php echo addslashes($facebookNoEscape['definition']) ?>'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制