Reputation: 129
i am unable to access response of webservice please help me error is coming i have alert it by parsing but it is showing error null. i am using online webservice
var webMethod = "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit";
var soap ='<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/"> <soap:Body> <CelsiusToFahrenheit xmlns="http://tempuri.org/"> <Celsius>12</Celsius> </CelsiusToFahrenheit> </soap:Body> </soap:Envelope>';
$j.ajax({
type: "POST",
url :webMethod,
data: soap,
dataType :"xml",
contentType:"text/xml; charset=\"utf-8\"",
cache:false,
async: false,
error:function(resp)
{
alert("Error :"+$j.parseXML(resp));
},
}).done(function(response){
console.log(response);
var xmlData =$j(response).find('FahrenheitToCelsiusResult').text();
alert(xmlData);
});
});
Upvotes: 0
Views: 249
Reputation: 4228
It's probably a cross-origin access problem. Browsers normally wont allow you to fetch remote data via AJAX. Using a JSONP interface is a common work-around for this problem.
Alternatively if you have control of the remote server (in your example this is unlikely) then you can add a header:
Access-Control-Allow-Origin: *
See: Wikipedia
I should add that another solution is to make your own local script (eg. PHP) on the same domain, which your Javascript can communicate locally with. The script would handle the actual SOAP communication (and therefore doesn't have to worry about cross origin policies) and simply returns the result.
Upvotes: 1