dst2017 2015-01-16 21: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 21: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" );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作