Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call my web service if requires one parameter

Status
Not open for further replies.

G00GLER

Instructor
May 17, 2005
57
0
0
US
pretty sure it's simple answer but so many ajax articles and none of my searches have returned a solution.

Trying to reference my .net web service that recieves a string and returns a string.

i seem to be getting an error on this line whatsthematter.asmx/SayHello");

function call_server()
{
request.open("GET", "whatsthematter.asmx/SayHello");
request.onreadystatechange = sever_interaction;
request.send('somenumber');

}

full code

webservice function
Code:
    public string SayHello(string yourname) {
        string returnme ="";
        returnme="Hello there "+yourname+"."; 
        return returnme;
    }
html page
Code:
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head>
<script>
function creat_Object()
{ 
var xmlhttp;
// This if condition for Firefox and Opera Browsers 
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
{
try 
{
xmlhttp = new XMLHttpRequest();
} 
catch (e) 
{
alert("Your browser is not supporting XMLHTTPRequest");
xmlhttp = false;
}
}
// else condition for ie
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}

var request = creat_Object();
function sever_interaction()
{
if(request.readyState == 1)
{
document.getElementById('aja_cnts').innerHTML='';
document.getElementById('aja_cnts').innerHTML = "<span style='background-color:orange;'>Loading...</span>";
}
if(request.readyState == 4)
{
var answer = request.responseText;
document.getElementById('aja_cnts').innerHTML='';
document.getElementById('aja_cnts').innerHTML = answer;
}
}
function call_server()
{
request.open("GET", "whatsthematter.asmx/SayHello"); 
request.onreadystatechange = sever_interaction;
request.send('somenumber');

}
</script>
</head>
<body>
<table width="80%" border="1" cellspacing="2">
<caption>
Using AJAX
</caption>
<tr>
<td width="16%" height="90"> </td>
<td width="23%"><label>
<input type="button" name="Button" value="Button" onclick="call_server();" />
</label></td>
<td width="61%"><div id="aja_cnts"> </div></td>
</tr>
</table>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top