duanjue6584 2014-07-26 05:33 采纳率: 100%
浏览 91
已采纳

在javascript函数调用中由于单引号导致的错误

I am passing value dynamically to javascript function.

I am retrieving data from database and filling to javascript function, it does not have a static binding.

share_it(data_from_mysql_database);

like

share_it('value from mysql database');

Some times value contain a single quote (').

like: share_it(' Essentially you'll have to have a good academic history ');

So function call gives error that:

Uncaught SyntaxError: Unexpected identifier 
  • 写回答

4条回答 默认 最新

  • dsbqfrr098575666 2014-07-26 05:42
    关注

    You ought to be converting special chars on the upstream rather than the downstream. Converting it on the upstream saves time later when an inexperienced developer does not care to escape the data on the downstream when sent to the client. Since you have not properly converted the data on the upstream, you have no choice. You should escape it.

    share_it(escape(data_from_mysql_database));
    

    Example"

    > escape("You're awesome");
    'You%27re%20awesome'
    > 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表