Calling parameterized XML web service from javascript

Posted By  Prajeesh On 18 May 2010 08:05:39
emailbookmarkadd commentsprint
No of Views:830
Bookmarked:0 times
Votes:0 times

Introduction

In a previous post i have explained about calling a web service from javascript, please see this post to see calling a web service without parameters.Suppose you have a web service that accepts user name and password and 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://2test.hopto.org/Leadservice.asmx/GetLeadCounts?UserName=Prajeesh&Password=123456";; //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>

thank you

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
By:Geez, this is awful.Date Of Posted:2/15/2012 2:15:54 AM
What?
wow. this is just....bad.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top