admin管理员组文章数量:1292698
I have this simple code to query against the web service:-
$.get( url ,
function(xml) {
var hello = $(xml).find("hello").text();
...
alert(xml); // displays [object XMLDocument]
alert($(xml)); // displays [object Object]
}
);
This works fine, but I'm interested to see entire XML structure from the callback function for debugging purpose. I tried a few things, but I couldn't get it to display the XML. What I want to see is something like this:-
<stuff>
<hello>bear</hello>
</stuff>
Any clue? Thanks.
I have this simple code to query against the web service:-
$.get( url ,
function(xml) {
var hello = $(xml).find("hello").text();
...
alert(xml); // displays [object XMLDocument]
alert($(xml)); // displays [object Object]
}
);
This works fine, but I'm interested to see entire XML structure from the callback function for debugging purpose. I tried a few things, but I couldn't get it to display the XML. What I want to see is something like this:-
<stuff>
<hello>bear</hello>
</stuff>
Any clue? Thanks.
Share Improve this question asked Feb 1, 2011 at 16:33 limclimc 40.2k22 gold badges104 silver badges145 bronze badges 1- 1 Why don't you just use Firebug? – SLaks Commented Feb 1, 2011 at 16:40
2 Answers
Reset to default 5If you are using firebug in firefox, but may also work in IE8 or chrome, you can try:
console.dirxml(xml)
OR
console.dir(xml)
OR
console.log(xml)
In IE8 press F12 to open up the developers console or you may get the error saying the normal browser doesn't know what console is (after F12 it should).
Alternatively you could use prettyPrint to display the object. Or take a look at the answer to Is there an equivalent for var_dump (PHP) in Javascript?
You would need a little trickery. Introduce a new element, which wraps your XML and output the .html()
from that. Like
var fakexml = "<stuff><hello>bear</hello></stuff>";
alert($('<debug>').append(fakexml).html());
or use .wrapAll()
alert($(fakexml).wrapAll('<debug>').parent().html());
本文标签: javascriptHow to display entire XML from JQuery39s AJAX callback functionStack Overflow
版权声明:本文标题:javascript - How to display entire XML from JQuery's AJAX callback function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741563250a2385569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论