zoukankan      html  css  js  c++  java
  • $.ajax()调用.cs里的方法实现ajax操作示例

    一、cs代码(返回一个字符串,方法必须是静态方法,且标识WebMethod

    //<summary>

            //获取历史记录表格

            //</summary>

            //<param name="preceptUid"></param>

            //<returns></returns>

            [System.Web.Services.WebMethod]//1、这个命名空间很关键,必须指明

            public static string GetCommentList(string DataLocator)//2static很关键,必须是静态方法

            {

                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                EntitySet<WorkItem> workItems;

                if (string.IsNullOrEmpty(DataLocator))

                {

                    return null;

                }

                else

                {

                    workItems = new WorkFlowBLL().GetCommentInOut(DataLocator);

                    for (int i = 0; i < workItems.Count; i++)

                    {

                        sb.Append("<div>");

                        WorkItem workItem = workItems[i];

     

                        //处理步骤信息                 

                        sb.Append("<font style='color:#f00;'><b>" + workItem.Alias + "</b></font>&nbsp;");

     

                        //处理人信息

                        sb.Append("【");

                        if ((workItem.AssigneeID != null) &&

                                (workItem.AssigneeID != Guid.Empty) &&

                                (workItem.PartName != workItem.AssigneeName))

                        {

                            sb.Append(string.Format("{0}(代{1}办)", workItem.AssigneeName, workItem.PartName));

                        }

                        else

                        {

                            sb.Append(workItem.PartName);

                        }

                        sb.Append("&nbsp;");

                        if ((workItem.AssigneeID != null) &&

                                (workItem.AssigneeID != Guid.Empty))

                        {

                            sb.Append(workItem.AssigneeDeptName);

                        }

                        else

                        {

                            sb.Append(workItem.PartDeptName);

                        }

                        sb.Append("&nbsp;");

                        if ((workItem.AssigneeID != null) &&

                                (workItem.AssigneeID != Guid.Empty))

                        {

                            sb.Append(workItem.AssigneeRank);

                        }

                        else

                        {

                            sb.Append(workItem.PartRank);

                        }

                        sb.Append("】<br />");

     

                        //时间信息

                        if (workItem.FinishTime != null && workItem.FinishTime.Value != DateTime.Parse("2100-12-31 23:59:59"))

                        {

                            sb.Append(workItem.FinishTime.Value.ToString("yyyy年MM月dd日 HH:mm"));

                        }

                        else if (workItem.ReadTime != null)

                        {

                            sb.Append(workItem.ReadTime.Value.ToString("yyyy年MM月dd日 HH:mm"));

                        }

                        else

                        {

                            sb.Append(workItem.ReceTime.Value.ToString("yyyy年MM月dd日 HH:mm"));

                        }

                        sb.Append("<br />");

     

                        //处理意见

                        sb.Append(workItem.PartComment);

     

                        sb.Append("<br />");

                        sb.Append("<br />");

     

                        sb.Append("</div>");

                    }

                }

                sb.Append("<a name='#anchorTO'></a>");

                return sb.ToString();

            }

     

    二、html代码(注意格式,使用result.d获取方法返回的值)

    $.ajax({

                    type: 'POST',

                    async: false,//如不设置此属性,请求的数据将可能不是最新的而是上次请求的数据

                    contentType: 'application/json',

                    url: 'ToDoList.aspx/GetCommentList',

                    dataType: 'json',//这段代码格式基本固定

                    data: '{"DataLocator":"' + data_locator + '"}',// 1、注意参数传入的格式(引号)

                    error: function (err) {

                        $menuDiv.html('出错了,错误信息:' + err + ',请重试!');

                    },

                    success: function (result) {

                        $menuDiv.html(result.d);//2、用result.d获取cs方法返回的数据

                        window.location = "#anchorTO";

                    }

                });

     

  • 相关阅读:
    在Fedora10上安装MySQL5.0.18,告捷!
    直接修改class文件内容即使是文本会导致App异常,正确方式是修改java再用生成的class替换掉原有的class
    生命的真谛不在于你呼吸的次数,而在于那些令你无法呼吸的时刻
    开放Fedora10自带的MySQL5.0.67的对外数据库服务
    重装上了Fedora8自带的MySQL5.0.45,再试,告捷!!
    Shell程序荟萃
    程序的价值
    两条Find指令
    Linux防火墙配置
    在Foreda8上安装libaio-0.3.105-2.i386.rpm
  • 原文地址:https://www.cnblogs.com/kevin860/p/7834438.html
Copyright © 2011-2022 走看看