首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在jquery中使用数据库中的结果

如何在jquery中使用数据库中的结果
EN

Stack Overflow用户
提问于 2014-03-07 05:08:21
回答 1查看 94关注 0票数 0

如何从“.$user”CONTENT“”加载内容。“在文本字段中?如果有任何解决方案,请帮助我

谢谢

代码语言:javascript
复制
           $('#add-max').ready(function(){

            $.gritter.add({

           // (string | mandatory) the heading of the notification

            title: 'This is a notice with a max of 3 on screen at one time!',
            // (string | mandatory) the text inside the notification

            text: 'HERE ',
            // (string | optional) the image to display on the left
            image: 'http://a0.twimg.com/profile_images/59268975/jquery_avatar_bigger.png',
            // (bool | optional) if you want it to fade out on its own or just sit there
            sticky: false,
            // (function) before the gritter notice is opened
            before_open: function(){
                if($('.gritter-item-wrapper').length == 3)
                {
                    // Returning false prevents a new gritter from opening
                    return false;
                }
            }
        });

        return false;

    });
EN

回答 1

Stack Overflow用户

发布于 2014-03-07 06:07:02

您将在PHP视图/输出文件中执行类似以下操作:

代码语言:javascript
复制
<html>
   <head>
   </head>
   <body>
       <!-- content -->

       <!-- assign js vars from PHP here -->
       <script type="text/javascript">
          var userContent = <?php echo $user['Content']; ?>
       </script>

       <!-- load your other custom JS files after. Best practice is to put these at the bottom of <body> -->
       <script type="text/javascript" src="/your/javascript/file/here.js"></script>
   </body>
</html>

基本上,您可以在任意javascript标记块中声明一个javascript变量,并将PHP数据回显到该变量中。

然后,所有后续脚本都可以访问该变量,您可以随心所欲地使用它。

因此,要使用jQuery代码,需要将前面定义的userContent变量作为text字段的值。

代码语言:javascript
复制
       $('#add-max').ready(function(){

        $.gritter.add({

       // (string | mandatory) the heading of the notification

        title: 'This is a notice with a max of 3 on screen at one time!',
        // (string | mandatory) the text inside the notification

        text: userContent,
        // (string | optional) the image to display on the left
        image: 'http://a0.twimg.com/profile_images/59268975/jquery_avatar_bigger.png',
        // (bool | optional) if you want it to fade out on its own or just sit there
        sticky: false,
        // (function) before the gritter notice is opened
        before_open: function(){
            if($('.gritter-item-wrapper').length == 3)
            {
                // Returning false prevents a new gritter from opening
                return false;
            }
        }
    });

    return false;

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22236017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档