C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » AJAX »

Calling a webservice using Javascript


Posted Date: 06 Nov 2009    Resource Type: Code Snippets    Category: AJAX
Author: PrajeeshMember Level: Gold    
Rating: 1 out of 5Points: 10



In some situations we may need to call a webservice and show the result of the webservice to the user without postback, you can achieve this using javascript.
Below is the code snippet I have used:

Following is the xml code returned by the web service

<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://tempuri.org/">1</int>


Javascript code to call webservice

var returned_data;
var request = new XMLHttpRequest();

function used to initialize the webservice

function initializeWebservice()
{
var url="http://webserviceprovider.org/Leadservice.asmx
GetLeadCounts?UserName=Prajeesh&Password=123456";; //Web service url
request.onreadystatechange = webStatusProc;
request.open( "GET", url, true );
request.send();
}


Follwoing function is used to process the webservice

function webStatusProc()
{
if (request.readyState == 4) // checking request completed or not?
{
response = request.responseXML.toXML();
XML = XMLDOM.parse( response);
returned_data= XML.evaluate('string(/int)');
alert(returned-data); //alerted returned data for testing
//you can do anything with returned data
}
}



Responses

Author: ABitSmart    06 Nov 2009Member Level: Diamond   Points : 0
Please format your code block.


Author: Prajeesh    06 Nov 2009Member Level: Gold   Points : 0
Formated the code


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
XML  .  Web Services  .  Javascript  .  AJAX  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Rotating an adrotator image without using xml file
Return to Discussion Resource Index
Post New Resource
Category: AJAX


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use