title: Parsing XML JQuery Ajax Response with Namespace
body: <p>I'm executing a web service call using JQuery and it's ajax function and I'm unable to parse the data coming back.  When I alert the data (alert($(data).find("return").text()) its empty.  I see the server responding with xml data as outlined below and when I alert(data) I get [object XMLDocument].  Is txt = $(data).find("return").text() valid given my XML structure with a namespace below?  I can see the full xml string in firebug. Any ideas?</p>
  
  <p>var txt = $(data).find("ns1\:return").text(); works on Chrome and Firefox, but not Safari </p>
  
  <p><strong>index.js:</strong></p>
  
  <pre><code>$(function () {
  $.ajax({
                  url: url,
                  success: function (data) {
                      var ndx = 0,
                          row,
                          **txt = $(data).find("return").text(),**
                          xml = unescape(txt),
                          xmlDoc = $.parseXML(xml),
                          firstrow = $(xmlDoc).find(
                                  "results").children(":first");
  
                      // populate the table based on the results returned by
                      // the web service
                      $("table.results thead").empty();
                      $("table.results tbody").empty();
                      row = $("&lt;tr/&gt;");
  
                      row.append($("&lt;th/&gt;").text("#").addClass("ndx"));
                      firstrow.children().each(function () {
                          row.append($("&lt;th/&gt;").text(this.nodeName));
                      });
                      row.appendTo($("table.results thead"));
  
                      $(xmlDoc).find("row").each(function () {
                          row = $("&lt;tr/&gt;");
                          row.append($("&lt;td/&gt;").text(ndx + 1).addClass("ndx"));
                          $(this).children().each(function () {
                              row.append($("&lt;td/&gt;").text($(this).text()));
                          });
                          row.appendTo($("table.results tbody"));
                          ndx++;
                      });
  
                      // clear the table if no results were returned
                      if (ndx == 0) {
                          // no rows returned
                          $("table.results thead").empty();
                          $("table.results tbody").empty();
                      }
  
                      statusNotice("Records Returned: " + ndx);
                  },
                  error: function(XMLHttpRequest, textStatus, errorThrown) {
                      // display the error returned by the web service
                      var xmlDoc = $(XMLHttpRequest.responseXML);
                      statusError(xmlDoc.find("Text").text());
                  },          
                  complete: function(XMLHttpRequest, textStatus) {
                      // hide the busy dialog
                      $("#busy-dlg").dialog("close");
                  }
              });
         });
  </code></pre>
  
  <p><strong>index.html:</strong>
      
      
      
      
      Demo
      
      
      </p>
  
  <pre><code>&lt;script type="text/javascript" src="js/jquery-1.6.4.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery-ui-min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery.layout-latest.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  //table displaying results from ajax call here
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>XML:</strong></p>
  
  <pre><code>&lt;ns1:executeResponse xmlns:ns1="http://sqlws.test.com"&gt;
  &lt;ns1:return&gt;
      &lt;results&gt;
          &lt;row&gt;
              &lt;attribute1&gt;value1&lt;/attribute1&gt;
              &lt;attribute2&gt;value2&lt;/attribute2&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;attribute1&gt;value1&lt;/attribute1&gt;
              &lt;attribute2&gt;value2&lt;/attribute2&gt;
          &lt;/row&gt;
      &lt;/results&gt;
  &lt;/ns1:return&gt;
  &lt;/ns1:executeResponse&gt; 
  </code></pre>