admin管理员组文章数量:1290547
a webservice returns some data to me. The data is actually just raw HTML (so no XML header, or tags around it, but just a piece of html).
<div class="Workorders">
<div id="woo_9142" class="Workorder">
<span class="Workorder">S1005</span>
<span class="Pn">30-2</span>
<span class="Description">Cooling Fan</span>
<span class="Shortages">3616-1 (SV)</span>
<span class="Company">xxx</span>
</div>
<div id="woo_9143" class="Workorder">
<span class="Workorder">S1006</span>
<span class="Pn">30-2</span>
<span class="Description">Cooling Fan</span>
<span class="Shortages">3616-1 (SV)</span>
<span class="Company">xxx</span>
</div>
</div>
If this were XML like so:
<workorders>
<workorder id="woo_9142">
<partnumber>30-2</partnumber>
</workorder>
</workorders>
I could go like this in jQuery:
$('/workorders/workorder', data).each(function() {
//This would give every partnumber $('partnumber', this).text();
});
How can I parse the returned HTML (like described at the beginning)?
myNamespace.onSuccess = function(request) {
//request contains the raw html string returned from the server
//How can I make this possible:
$(request).find('div.Workorders div.Workorder').each(function() {
//Do something with the Workorder DIV in 'this'
});
}
a webservice returns some data to me. The data is actually just raw HTML (so no XML header, or tags around it, but just a piece of html).
<div class="Workorders">
<div id="woo_9142" class="Workorder">
<span class="Workorder">S1005</span>
<span class="Pn">30-2</span>
<span class="Description">Cooling Fan</span>
<span class="Shortages">3616-1 (SV)</span>
<span class="Company">xxx</span>
</div>
<div id="woo_9143" class="Workorder">
<span class="Workorder">S1006</span>
<span class="Pn">30-2</span>
<span class="Description">Cooling Fan</span>
<span class="Shortages">3616-1 (SV)</span>
<span class="Company">xxx</span>
</div>
</div>
If this were XML like so:
<workorders>
<workorder id="woo_9142">
<partnumber>30-2</partnumber>
</workorder>
</workorders>
I could go like this in jQuery:
$('/workorders/workorder', data).each(function() {
//This would give every partnumber $('partnumber', this).text();
});
How can I parse the returned HTML (like described at the beginning)?
myNamespace.onSuccess = function(request) {
//request contains the raw html string returned from the server
//How can I make this possible:
$(request).find('div.Workorders div.Workorder').each(function() {
//Do something with the Workorder DIV in 'this'
});
}
Share
Improve this question
asked Jun 23, 2009 at 12:46
RopstahRopstah
17.8k26 gold badges123 silver badges199 bronze badges
4
- 1 You should use a <table> for this kind of data though. – Gab Royer Commented Jun 23, 2009 at 12:50
- Do i? ;) Every DIV has different 'viewtypes' which are built based on CSS... – Ropstah Commented Jun 23, 2009 at 12:55
- You should probably read this : stackoverflow./questions/30251/tables-instead-of-divs It wouldn't be too hard to change only your CSS selector I think. – Gab Royer Commented Jun 23, 2009 at 12:58
- Lol, -read- my ment. I really need divs – Ropstah Commented Jun 23, 2009 at 13:02
3 Answers
Reset to default 7something like
myNamespace.onSuccess = function(request) {
$(request.responseText).filter('div.Workorder').each(function() {
$('span.Pn', $(this)).text();
});
}
Have you tried adding the html to the dom, hiding it and then process it:
myNamespace.onSuccess = function(request) {
var hidden = document.createElement ( 'div' );
hidden.id = 'hiddenel';
$("body").append ( hidden );
$("#hiddenel").css ( 'visibility', 'hidden' );
$("#hiddenel").html ( resp );
$("#hiddenel").find ( 'div.Workorders div.Workorder').each(function() {
.....
});
}
You can specify explicitly the return type you are expecting: http://docs.jquery./Specifying_the_Data_Type_for_AJAX_Requests
本文标签: JavascriptjQueryParse returned 39data39 as HTML for further selectingStack Overflow
版权声明:本文标题:JavascriptjQuery - Parse returned 'data' as HTML for further selecting? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741499597a2381996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论