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 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换