dongluo8439 2014-07-24 13:52
浏览 17
已采纳

在jquery中显示数据库的结果

How can I use the content in $displayusercontent which is pulled from the db into the Text field on the jquery.

I've tried this below, but nothing returns, if I echo $displayusercontent on to the page then it works this way.

<html>
<head>
</head>
<body>
   <!-- my content here-->

   <script type="text/javascript">
      var userContent = <?php echo $displayusercontent; ?>
   </script>       
   <script type="text/javascript" src="/my/javascript/file/here.js"></script>
</body>
</html>

This is from my jquery file

initIntro: function () {
// display marketing alert only once
if (!$.cookie('intro_show')) {
    setTimeout(function () {
        var unique_id = $.gritter.add({
            // (string | mandatory) the heading of the notification
            title: 'MyTitle',
            // (string | mandatory) the text inside the notification
            text: userContent,
            // (string | optional) the image to display on the left
            //image: '../../assets/local/layout/img/avatar.png',
            // (bool | optional) if you want it to fade out on its own or just sit there
            sticky: true,
            // (int | optional) the time you want it to be alive for before fading out
            time: '',
            // (string | optional) the class name you want to apply to that specific message
            class_name: 'my-sticky-class'
        });

        // You can have it return a unique id, this can be used to manually remove it later using
        setTimeout(function () {
            $.gritter.remove(unique_id, {
                fade: true,
                speed: 'slow'
            });
        }, 15000);
    }, 2000);

    $.cookie('intro_show', 1);
}
}
  • 写回答

2条回答 默认 最新

  • duan201444 2014-07-24 13:59
    关注

    It's invalid. You need to make it a string

    var userContent = <?php echo json_encode($displayusercontent); ?>;
    

    As @dsclementsen pointed out, in this case using json_encode is the right option.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端