0
For example :
<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://tempuri.org/">1</int>
You can use following code snippet to call a web service from javascript:
<script language="text/javascript">
var returned_data;
var request = new XMLHttpRequest();
//function to initialize web service
function initializeWebservice()
{
var url = http://Localhost/Testwebservice.asmx/GetLeadCounts; //Web service url
request.onreadystatechange = webStatusProc;
request.open( "GET", url, true );
request.send();
}
//function to process webservice response
function webStatusProc()
{
if (request.readyState == 4) // Request completed?
{
response = request.responseXML.toXML();
XML = XMLDOM.parse( response);
returned_data= XML.evaluate('string(/int)');
alert(returned-data);
//do anything with returned data
}
}
</script>
Posted on 2:46 PM by prajeesh and filed under
Javascript,
web service
Suppose you have a web service that returns a value in XML format and you want to show the returned value in a webpage or a widget.For example :
<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://tempuri.org/">1</int>
You can use following code snippet to call a web service from javascript:
<script language="text/javascript">
var returned_data;
var request = new XMLHttpRequest();
//function to initialize web service
function initializeWebservice()
{
var url = http://Localhost/Testwebservice.asmx/GetLeadCounts; //Web service url
request.onreadystatechange = webStatusProc;
request.open( "GET", url, true );
request.send();
}
//function to process webservice response
function webStatusProc()
{
if (request.readyState == 4) // Request completed?
{
response = request.responseXML.toXML();
XML = XMLDOM.parse( response);
returned_data= XML.evaluate('string(/int)');
alert(returned-data);
//do anything with returned data
}
}
</script>
Post a Comment