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 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面