dst2017 2015-01-16 13:49
浏览 74
已采纳

使用jQuery load()函数传递Php变量

I am trying to pull a portion of a plugin into the wordpress homepage using the jQuery .load() method and I'm a little tripped up on the syntax on how to just pull in a section of the page. Heres my code:

            //Get Current user and Home url
              global $current_user;
              get_currentuserinfo();
              $kd_bpuser = $current_user->user_login;
              $homeurl = get_home_url();
            ?>

            <script>
            //Pass home url and current user to javascript
              var bpUser = <?php echo json_encode($kd_bpuser); ?>;
              var bpUrl = <?php echo json_encode($homeurl); ?>;
              var bpFullUrl = bpUrl +"/members/" + bpUser + "/forums/subscriptions/"; 
              var bpData = "#bbp-author-unread-topics";
              // console.log(bpFullUrl);
              // console.log(bpUser);
              // console.log(bpUrl);
            </script>


            <div id="bbpress-forums">  

             <script type="text/javascript">

                  //pull in members subscriptions page unread forum topics
                  jQuery( document ).ready(function( $ ) {
                    $("#bbpress-forums").load(bpFullUrl, bpData);
                  });

              </script>



            </div><!-- end bbpress-forums--> 

Currently it just pulls in the whole page but I want it to just pull in this section: #bbp-author-unread-topics. Any help would be appreciated!

展开全部

  • 写回答

1条回答 默认 最新

  • duangu4980 2015-01-16 13:56
    关注

    The selector portion of load() url needs to be part of the url string with a space separator. You are passing it as a separate argument

    Try:

    $("#bbpress-forums").load(bpFullUrl + ' ' +  bpData);
    

    See example in load() docs under section "Loading Page Fragments"

    $( "#result" ).load( "ajax/test.html #container" );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部