Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display object.responseXML text for debugging

I'm using the following script:

<script type="text/javascript"> 
    function processResult(xData, status) { 
       $('.feedbackLink').empty(); 
        alert ($(xData.responseXML.xml));
        console.log($(xData.responseXML.xml));
        $(xData.responseXML).find("z\\:row").each(function() { 
            alert ($(this));
            var title = $(this).attr("ows_Title"); 
            var url = $(this).attr("ows_Contact"); 
            $('.feedbackLink').append("<a href="+url+">"+title+"</a>"); 
       }); 

   };

   $(document).ready(function() { 
   alert("ready"); 
       var soapEnv = "<?xml version='1.0' encoding='utf-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soapenv:Body> <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> <listName>Pages</listName> <viewFields> <ViewFields> <FieldRef Name='Title' /> <FieldRef Name='Contact' /> </ViewFields> </viewFields> </GetListItems> </soapenv:Body> </soapenv:Envelope>";       
       $.ajax({ 
           url: "/_vti_bin/lists.asmx", 
           type: "POST", 
           dataType: "xml", 
           data: soapEnv, 
           complete: processResult, 
           contentType: "text/xml; charset=\"utf-8\"" 
       });
       alert(soapEnv); 
   }); 

    </script>

But the alert within $(xData.responseXML).find("z\\:row").each(function() { wont fire. How can I view the responseXML? I want to double check I'm looking for the right identifiers (I dont know where the ows_ came from, I was given this script to work with).

The alert and console.log just displays [object Object].

Any advice on how to debug this?

like image 353
RyanS Avatar asked Apr 12 '12 12:04

RyanS


3 Answers

Try using console.log(xData.responseText) to get in the console the actual xml instead of [object Object].

like image 151
Maria Ioannidou Avatar answered Nov 08 '22 14:11

Maria Ioannidou


in IE:

alert(xData.responseXML.xml);

in Firefox (unconfirmed):

var string = (new XMLSerializer()).serializeToString(xData.responseXML); alert(string);

to see the full xml, you can append it to the page (IE):

function processResult(xData, status) 
{
    document.body.innerHTML += htmlEncode(xData.responseXML.xml);
}
function htmlEncode(str)
{
    return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

xData.responseXML.xml is the xml as a string, so converting it to a jquery object isnt needed

like image 29
user1566694 Avatar answered Nov 08 '22 16:11

user1566694


Try using firebug for firefox to see error messages and messages produced by console.log.

like image 21
Brant Olsen Avatar answered Nov 08 '22 16:11

Brant Olsen