1. WebServices.aspx
![](http://img.e-com-net.com/image/product/eab1c1ad3d6344f98e3a6ee4266d96df.gif)
<%
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
@ Page Language="C#" AutoEventWireup="true" CodeFile="WebServices.aspx.cs" Inherits="WebServicesTest" %>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<head runat="server">
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<title>AjaxWebServiceTest</title>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</head>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<body>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<form id="form1" runat="server">
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<asp:ScriptManager ID="ScriptManager1" runat="server">
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<Services>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<asp:ServiceReference Path="../WebService/AjaxService.asmx" />
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</Services>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</asp:ScriptManager>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<ProgressTemplate>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<img src="../Images/loading.gif" />
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
Loading
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</ProgressTemplate>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</asp:UpdateProgress>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<div>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<input id="inputName" type="text" size="20" runat="server" />
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
<input id="btnTest" type="button" value="调 用" onclick="return btnTest_Click()" />
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</div>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</form>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</body>
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</html>
![](http://img.e-com-net.com/image/product/eab1c1ad3d6344f98e3a6ee4266d96df.gif)
<script type="text/javascript" language="JavaScript">
![](http://img.e-com-net.com/image/product/561925b32f8f4c9d9561af4d649930ae.gif)
function $(s)
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{return document.getElementById(s);}
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
function btnTest_Click()
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
var requestSimpleService = AjaxService.AjaxServiceTest(
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
$('<%=inputName.ClientID %>').value, //params
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
OnRequestComplete //Complete event
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
return false;
![](http://img.e-com-net.com/image/product/fd30ab844bef43f6b8a6ceb02f8ad366.gif)
}
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
function OnRequestComplete(result)
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
alert(result);
![](http://img.e-com-net.com/image/product/cc612d05a8624bada20221f76e20a5bc.gif)
}
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
</script>
2. AjaxService.asmx
![](http://img.e-com-net.com/image/product/eab1c1ad3d6344f98e3a6ee4266d96df.gif)
<%
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
@ WebService
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
Language="C#"
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
CodeBehind="~/App_Code/WebService/AjaxService.cs"
![](http://img.e-com-net.com/image/product/cc612d05a8624bada20221f76e20a5bc.gif)
Class="AjaxService" %>
3. AjaxService.cs
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
using System;
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
using System.Web.Services;
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
using System.Web.Script.Services;//***必须
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
[ScriptService]
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
public class AjaxService : WebService
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
public AjaxService()
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{ }
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
[WebMethod]
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
public string AjaxServiceTest(string s)
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
Framework.AppException.LogFile(s);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
return "Hello " + s;
![](http://img.e-com-net.com/image/product/fd30ab844bef43f6b8a6ceb02f8ad366.gif)
}
![](http://img.e-com-net.com/image/product/cc612d05a8624bada20221f76e20a5bc.gif)
}