Juery Ajax的两种使用方法

1、普通Web方法

           1)前台js代码

   <script type="text/javascript">
        $(document).ready(function () {
            //文件扩展属性修改
            $("input[name='DoEdit']").bind("click", function () {
                var id = $(this).parent().children(".ExendAttrID").val();
                window.location.href = "FileExtendedAttrUpdate.aspx?ExendAttrID=" + id;
            });
            //文件扩展属性删除
            $("input[name='DoDelete']").bind("click", function () {
                var id = $(this).parent().children(".ExendAttrID").val();
                if (confirm("您确定要删除此文件扩展属性项吗?")) {
                    $.ajax({
                        url: "FileExtendedAttrManagement.aspx/DeleteExtendAttr",
                        data: "{strID:'" + id + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json;charset=utf-8",
                        success: function (jd) {
                            var result = eval(jd);
                            if (result) {
                                alert("11111111");
                            }
                        },
                        error: function (req) {
                            //        alert(req.responseText);
                            alert("123");
                        }
                    });
                }
            });
        })
    </script>

 

   2)后台代码

using System.Web.Services;//添加引用

        /// <summary>
        /// 删除文件扩展属性
        /// </summary>
        /// <param name="strID">扩展属性ID</param>
        /// <returns>成功返回true 失败返回false</returns>
        [WebMethod]
        public static string  DeleteExtendAttr(string strID)
        {
            bool blnFlg = true;
            try
            {
                using (Interface.SystemConfiguration sysConfig = new Interface.SystemConfiguration())
                {
                    sysConfig.DeleteExtendedAttribute(long.Parse(strID));
                }
            }
            catch (Exception)
            {
                blnFlg = false;
                throw;
            }
            return blnFlg.ToString();
        }
               
    }

 

2、在MVC中的应用

前台JS代码:

http://blog.csdn.net/angle860123/article/details/7402396

后台代码:

[HttpPost]

private JsonResult ForgetLogin(参数string)

{

       return json数据格式

 }

 

两者的特性不一样,还有第一种必须是静态的方法

你可能感兴趣的:(Ajax,exception,function,String,input,扩展)