使用AJAX获取部分HTML [英] Get partial HTML with AJAX

查看:43
本文介绍了使用AJAX获取部分HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AJAX调用获取另一页的内容.我可以获取整个文档,但是是否可以获得更好的精度,并且只获取目标div内的某个部分?

I am trying to get a content of a another page using AJAX call. I am able to get the entire document but is it possible to get a better precision and get only a section that is within a target div?

<div class="myTarget">content that I need</div> 

这就是我现在得到的方式:

Here's how I get it now:

$.ajax({
    type: "GET",
    url: "/dir/targetPage",
    dataType: "html",
    success: function(data)
    {
      $('#dropHere').html(data);
    }
}); 

推荐答案

$('#dropHere').load('/dir/targetPage #ele');

其中"#ele"是ID为ele的元素,并且是所有内部子元素.

Where '#ele' is an element with the id of ele and all it's inner children.

这篇关于使用AJAX获取部分HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆