日期:2014-05-17 浏览次数:20761 次
$.ajax({ type: "POST", contentType: "application/json", url: "WebService1.asmx/Getstaff", data: "{currPage: '1', tabName: 'staff'}", dataType: 'json', success: function (data) { alert(data); } });
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using DataCall; using System.Data; using System.Text; namespace WebApplication1 { /// <summary> /// WebService1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { DAL dal = new DAL(); [WebMethod] /// <summary> /// 获取信息 /// </summary> /// <param name="currPage">当前页页码</param> /// <param name="showColumn">需要得到的字段</param> /// <param name="tabName">需要查看的表名</param> /// <param name="strCondition">查询条件</param> /// <param name="ascColumn">排序的字段名</param> /// <param name="bitOrderType">排序的类型 (0为升序,1为降序)</param> /// <param name="pkColumn">主键名称</param> /// <param name="pageSize">分页大小</param> /// <returns></returns> public string Getstaff(int currPage, string tabName) { DataTable dt = dal.GgtSatff(currPage, "*", tabName, "", "id", 0, "id", 5); string json = DataTable2Json(dt); return json; } #region dataTable转换成Json格式 ///<summary> /// dataTable转换成Json格式 ///</summary> ///<param name="dt"></param> ///<returns></returns> public static string DataTable2Json(DataTable dt) { StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.Append("{\""); jsonBuilder.Append(dt.TableName); jsonBuilder.Append("\":["); jsonBuilder.Append("[");