duan246558 2015-08-31 00:37
浏览 37
已采纳

使用Ajax引入特定元素

I am building a Wordpress site. I am using Ajax to pull in content from another page to fill an empty div when a particular element is clicked. Each element has a different URL so I made the Url a variable. I need Ajax to only pull in a particular element from this URL. Instead it keep pulling in the entire page. I've tried using various methods to select the specific element, but I've hit a wall and need a little help.

    (function($) {

        function find_page_number( element ) {
            return parseInt( element.html() );
        }

        $('.member-info').on('click', function (event) {
            event.preventDefault();

            page = find_page_number( $(this).clone() );

            var memberSrc = $(this).attr('href');

            $.ajax({

                url: memberSrc,
                type: 'get',
                dataType:'html',
                data: {
                    action: 'ajax_pagination',
                    query_vars: ajaxpagination.query_vars,
                    page: page
                },
                success: function( html ) {
                    $("#main").empty();
                    $('#main').append( html);
                }

            });

        })
    })(jQuery);

</div>
  • 写回答

1条回答 默认 最新

  • dqczgtem06898 2015-08-31 00:46
    关注

    You can filter the answer with jQuery:

    $('#main').append( $(html).find('#main').html() );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题