How to display all the XML from a jQuery AJAX callback function?

I have this simple code for requesting a 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 in seeing the whole XML structure from a callback function for the purpose of debugging. I tried a few things, but I could not get it to display XML. I want to see something like this: -

<stuff>
    <hello>bear</hello>
</stuff>

Any clue? Thank.

+3
source share
2 answers

If you use firebug in firefox, but can 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 the developer console, or you may receive a message that the regular browser does not know which console (after F12).

prettyPrint . var_dump (PHP) Javascript?

+5

. , XML .html() .

var fakexml = "<stuff><hello>bear</hello></stuff>";

alert($('<debug>').append(fakexml).html());

.wrapAll()

alert($(fakexml).wrapAll('<debug>').parent().html());
+1

Source: https://habr.com/ru/post/1789280/


All Articles