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?
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>');
    }
});
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);
         }
    });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With