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.