2

Apologise. I know this type of question was asked several times and was answered. I really spent a complete day on this and cant find any solution.

I am using Jquery SOAP API to submit a WSDL request and get the response. I am able to submit the request and also I am able to receive the response.

AJAX code

$(document).ready(function() {
    $('#btn_click').click(function(e) {
        // stop the form to be submitted...
        e.preventDefault();
        var data = $('#txt_userid').val();
        data = formUserNameReqXML(data);
        $.soap({
            url: 'service ws*l url',
            method: 'getUserName',
            data: data,
            success: function(xml) {
                $('#feedback').text(xml);
                alert($(xml).find('username').text());
            },
            error: function(SOAPResponse) {
                $('#feedback').text(SOAPResponse.toString());
            }
        });
    });
});

The returned XML is as given below

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ns1="urn:localhost-jeema"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:getUserNameResponse>
      <username xsi:type="xsd:string">SUCCESS</username>
    </ns1:getUserNameResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I want to get the value inside the 'username' tag. As in the above AJAX code the 'feedback' element is loaded with the response XML string (without line breaks) but the alert message is displaying null. Why the value received inside alert is empty?

The interesting part is that the same XML parsed perfect when I try with simple AJAX as given below.

$(document).ready(function() {
  $('#btn_click').click(function(e) {
    $.ajax({
    type: "POST",
    url: "response.xml",
    dataType: "xml",
    success: function(xml) {
      alert($(xml).find('username').text());
    },
    error:function() { alert('outside'); }
    });
  });
});

Need some experts advice on this.

2
  • Not sure I got it, the question was ? Commented Nov 16, 2013 at 20:38
  • Sorry if my query is confusing. My question is why the value is returning empty in my SOAP Ajax call even though the 'username' is a valid XML tag in my response? Commented Nov 16, 2013 at 21:08

1 Answer 1

2

Finally, parsed the XML successfully

success: function(xml) {
  var xml = xml.toString();
  alert($(xml).find('username').text());
}

The parsing happens after I covert the xml variable to String.

Sign up to request clarification or add additional context in comments.

2 Comments

i'am also facing the same problem
How do we get value of username when xml is like <ns0:username >1</ns0:username> instead of <username xsi:type="xsd:string">SUCCESS</username>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.