I want to call a web service of which URL is available to me. I want to just call it and retrieve the result back using javascript Ajax. For example : if some web service of like addition of two numbers is available freely and I want to use it in my app, how should I start ? I have just implemented following code (don't know it is right or not):
function webServiceCallResult(){
var xmlHttpReq = getXMLHttpRequest();
if(xmlHttpReq == null){
alert('Exception occurred');
return false;
}
var strURL = "http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml";
//var strURL = 'http://w3schools.com/dom/note.xml';
if(xmlHttpReq.readyState == 0){
xmlHttpReq.open('GET', strURL, true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpReq.onreadystatechange = function() {
if (xmlHttpReq.readyState == 4) {
var resultString = xmlHttpReq.responseXML;
document.getElementById('webserviceresponsetext').value = resultString.getElementsByTagName("website")[0].childNodes[0].nodeValue;
}
}
xmlHttpReq.send();
}
}
This is working fine in IE but giving error in FF, Opera etc.like
XML parsing error,no element found Location: moz-nullprincipal:{ce91453b-f84c-4ce8-b02c-b999ef9f013a} Line Number 1, Column 1
Is it even possible to call a web service without using SOAP service request ? Thanks..