ASP.NET AJAX中 复杂数据类型使用简单实例
2011-09-25 13:30
706 查看
aspx页面
ComplexType.asmx页面
Employee.cs类页面代码
<asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="ComplexType.asmx" /> </Services> </asp:ScriptManager> <input type="button" value="Double Salary" onclick="doubleSalary()" /> <input type="button" value="Reverse" onclick="reverse([1, 2, 3, 4, 5])" /> <input type="button" value="Get Employees" onclick="getEmployees()" /> <script language="javascript" type="text/javascript"> function doubleSalary() { var employee = new Object(); employee.FirstName = "Jeffrey"; employee.LastName = "Zhao"; employee.Salary = 1000; ComplexType.DoubleSalary(employee, doubleSalarySucceeded); } function doubleSalarySucceeded(result) { var message = String.format( "First Name: {0}\nLast Name: {1}\nFull Name: {2}\nSalary: {3}", result.FirstName, result.LastName, result.FullName, result.Salary); alert(message); } function reverse(array) { ComplexType.Reverse(array, function(result){alert(result);}); } function getEmployees() { ComplexType.GetEmployees(getEmployeesSucceeded); } function getEmployeesSucceeded(result) { for (var key2 in result) { alert(key2 + ": " + result[key2].Salary) } } </script>
ComplexType.asmx页面
<%@ WebService Language="C#" Class="ComplexType" %> using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Collections.Generic; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class ComplexType : System.Web.Services.WebService { [WebMethod] public Employee DoubleSalary(Employee employee) { employee.Salary *= 2; return employee; } [WebMethod] public List<int> Reverse(List<int> list) { list.Reverse(); return list; } [WebMethod] public IDictionary<string, Employee> GetEmployees() { Dictionary<string, Employee> result = new Dictionary<string, Employee>(); Employee emp1 = new Employee(); emp1.FirstName = "Jeffrey"; emp1.LastName = "Zhao"; emp1.Salary = 1000; result[emp1.FullName] = emp1; Employee emp2 = new Employee(); emp2.FirstName = "Tom"; emp2.LastName = "Chen"; emp2.Salary = 2000; result[emp2.FullName] = emp2; return result; } }
Employee.cs类页面代码
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// <summary> /// Summary description for Employee /// </summary> public class Employee { public string FirstName; public string LastName; public int Salary; public string FullName { get { return this.FirstName + " " + this.LastName; } } }
相关文章推荐
- ASP.NET AJAX中 复杂数据类型使用简单实例
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 在asp.net AJAX客户端使用复杂数据类型方法
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 在asp.net AJAX客户端使用复杂数据类型方法
- 在asp.net AJAX客户端使用复杂数据类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法:服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(5):服务器端和客户端数据类型的自动转换:基本类型和枚举类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(7):服务器端和客户端数据类型的自动转换:泛型集合类型
- asp.net 使用ajax请求地址接口数据 ajax返回类型是json js get post请求数据
- 通过实例模拟ASP.NET MVC的Model绑定机制:简单类型+复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(8):服务器端和客户端数据类型的自动转换:数组类型
- 1.简单实例:ASP.NET下Echarts通过Ajax从数据库中获取数据
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(7):服务器端和客户端数据类型的自动转换:泛型集合类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet