如何从具有HTML页面的responseText获取特定的div内容 [英] How to get the specific div content from responseText which have complate Html page

查看:711
本文介绍了如何从具有HTML页面的responseText获取特定的div内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在responseText中得到整个html页面,我只想解析/ 过滤responseText到 获取特定的div说测试和基础内容.我不会 想要修改服务器端代码以仅发送所需的div responseText.

I am getting the whole html page in responseText, i just want to parse/ filter the responseText to get a specific div say test and underlying contents. I would not like to modify the server side code to send just required div in responseText.

url: "Someurl",
datatype: "text/html",
success : function(responseText) 
{
    alert(responseText);
dat = $(data).filter("#test").html();
alert(dat);//getting null
$('#test').html(dat);

}

responseText包含

100行HTML ... .... ....还有更多div标签和其他 标签 .... 100行HTML

100's of HTML lines.... .... ....many more div tags and other tags .... 100's of HTML lines

我正在使用jquery并且尝试过

I'm using jquery and i tried

$(responseText).filter("#test").html();

并且也使用查找

推荐答案

如果响应中只有html并且打算使用唯一ID来确定DIV,那么它可能比我之前给出的示例更容易

If you have only html in the response AND your intention is to pinpoint a DIV using a unique ID, then it might be even easier than the example I gave earlier.

尝试这样的事情

var myHtml = $(responseText).find('#test').html();
//alert(myHtml); -- optional, just to verify

这篇关于如何从具有HTML页面的responseText获取特定的div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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