douruye5092 2017-05-02 07:21 采纳率: 100%
浏览 50

jQuery.jGrowl Uncaught SyntaxError:无效或意外的令牌

I know that this question have been asked before but I still couldn't find the solution for my problem.. The thing is.. it happens at production server, but works well in development. So I'm not sure whats wrong with it. Appreciate if you could advice. Thanks in advance.

The following is my code.. and I had this "Uncaught SyntaxError: Invalid or unexpected token" error on my jQuery.jGrowl

<script src="<?php echo base_url(); ?>js/jquery.jgrowl.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/jquery.jgrowl.css">
<?php $message  = $_SESSION['message'];
  if($message) { ?>
    <script>
      jQuery(function(){
        jQuery.jGrowl("<?php echo $message; ?>", { header: 'Message' });
      });
    </script>
    <?php $_SESSION['message'] = '';
  }
?>

I get this error:

Uncaught SyntaxError: Invalid or unexpected token

On this line:

jQuery.jGrowl("<?php echo $message; ?>", { header: 'Message' });
  • 写回答

1条回答 默认 最新

  • douban2014 2017-05-02 07:27
    关注

    I guess your $message string contains chars, which breaks the string. This could be a " or char. You could fix this by usig an escape function.

    json_encode should be sufficient

    jQuery.jGrowl(<?php echo json_encode($message); ?>, { header: 'Message' });
    

    Note, that i removed the " around the string.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog