admin管理员组文章数量:1321063
I am using the below script to load the html in my page. However it loads all of the page contents that is included in webpage.html means(from doctype to closing html tag).
$(function() {
$.ajax({
type:"GET",
url:"webpage.html",
dataType:"html",
success:function(data) {
alert(data);
$("body").html(data);
},
error:function() {
alert("Error");
}
})
});
I have no control over webpage.html, I actually just need a few divs with particular classes to load after an ajax Request. Can anyone give me some Idea as to how would I filter the webpage contents over an ajax Call for which I have no control.
Thanks, Mike
I am using the below script to load the html in my page. However it loads all of the page contents that is included in webpage.html means(from doctype to closing html tag).
$(function() {
$.ajax({
type:"GET",
url:"webpage.html",
dataType:"html",
success:function(data) {
alert(data);
$("body").html(data);
},
error:function() {
alert("Error");
}
})
});
I have no control over webpage.html, I actually just need a few divs with particular classes to load after an ajax Request. Can anyone give me some Idea as to how would I filter the webpage contents over an ajax Call for which I have no control.
Thanks, Mike
Share Improve this question asked Sep 11, 2013 at 19:27 MikeMike 3,41811 gold badges47 silver badges80 bronze badges 1- Possible duplicate of Extract part of HTML document in jQuery – Simon E. Commented Jul 3, 2017 at 5:42
2 Answers
Reset to default 3 success:function(data) {
var out = "";
$(data).find("your selectors").each(function(loop, item){
out += $(item).html();
});
data = out;
alert(data);
$("body").html(data);
}
Use .load()
var url = "webpage.html .classOfDivsYouWantLoaded";
$("body").load(url, function(){
//callback after your data is in loaded into body.
});
本文标签:
版权声明:本文标题:javascript - How to get a part of HTML webpage in a jQuery ajax Request? In other words how to filter the web page contents on a 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090447a2420232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论