Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display XML response from AJAX request in a PRE tag

I am using jquery to make an AJAX request to a web service which responds with XML:

$.ajax({
    type: "GET",
    url: $uri,
    dataType: "xml",
    async: false,
    contentType: "text/xml; charset=\"utf-8\"",
    complete: function(xmlResponse) {
        $("#preForXMLResponse").html(xmlResponse);
    }
});

I want to display the XML response from the web service in a HTML page inside PRE tag. But the code above does not work. How can I change the XML response to a string and display it inside PRE tag?

like image 666
Richard Knop Avatar asked Oct 27 '25 05:10

Richard Knop


2 Answers

Try this

$.ajax({
    type: "GET",
    url: $uri,
    dataType: "xml",
    async: false,
    contentType: "text/xml; charset=\"utf-8\"",
    success: function(xmlResponse) {
        $("#preForXMLResponse").html('<pre>'+xmlResponse+'</pre>');
    }
});
like image 58
ShankarSangoli Avatar answered Oct 29 '25 18:10

ShankarSangoli


Try this:

$(function(){

    $.ajax({
         type: "GET",
         url: $uri,
         dataType: "xml",
         async: false,
         contentType: "text/xml; charset=\"utf-8\"",
         complete: function(xmlResponse) {

                // So you can see what was wrong...
                console.log(xmlResponse);
                console.log(xmlResponse.responseText);

              $("#preForXMLResponse").text(xmlResponse.responseText);
         }
    });

});
like image 38
hasser Avatar answered Oct 29 '25 19:10

hasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!