如何从具有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