Here is the code for calling a web service using jQuery
<html>
<head id="Head1" runat="server">
<title>ASP.NET AJAX Web Services: Web Service Sample
Page</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jQuery/1.2.6/jQuery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#btnTest").click(function(event) {
$.ajax({
type: "POST",
url: "dummyWebsevice.asmx/HelloToYou",
data: "{'name': '" + $('#name').val() + "'}",
contentType: "application/json;
charset=utf-8",
dataType: "json",
success: function(msg)
{
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' +
result.statusText);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h1> Calling Web Services using jQuery </h1>
Enter your name:
<input id="name" />
<br />
<input id="btnTest"
value="Test
WebService"
type="button" />
</form>
</body>
</html>
Here is the code for calling a web service using ASP.NET Ajax:
<html>
<head id="Head1" runat="server">
<title>Calling Web Services using asp.net ajax</title>
<script type="text/javascript">
function OnClick() {
var txtName = $get("name");
dummyWebservice.HelloToYou(txtName.value, SayHello);
}
function SayHello(result) {
alert(result);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="_scriptManager"
runat="server">
<Services>
<asp:ServiceReference Path="dummyWebsevice.asmx"
/>
</Services>
</asp:ScriptManager>
<h1>Calling Web Services using asp.net ajax </h1>
Enter your name:
<input id="name" />
<br />
<input id="btnTest"
value="Test"
type="button"
onclick="OnClick();"
/>
</form>
</body>
</html>