jquery调用一般处理程序

$.ajax({
type: 'post',
url: 'ContactAction.ashx',
dataType: "json",
data: { action: $("#action").val(), userId: $("#editId").val(), ContactName: ContactName, OrgName: OrgName, telphone: telphone, mobile: mobile, email: email, FaxNo: FaxNo, QQNo: QQNo, WeChatNo: WeChatNo, address: address, postcode: postcode }, //调用获取表单数据的方法
success: function (data) {
if (data.Status == "1") {
$('#myModal').modal('hide');
g.bootstrapTable('refresh', { query: { offset: 0, name: searchName} });

layer.alert(data.Msg, {
title: ['提示', 'font-size:18px;color:#fff;background-color:#5cb85c;border-color:#4cae4c'],
//skin: 'layui-layer-molv', //样式类名 layui-layer-lan layui-layer-molv
closeBtn: 1, //0:不显示;1:窗口里 2:窗口外
icon: 1 //1:成功 2:错误 3:问号 4:锁 5:哭脸 6:笑脸
//shift: 4 //动画类型
});
}
else {
layer.alert(data.Msg, {
title: ['错误', 'font-size:18px;color:#fff;background-color:#d9534f;border-color:#d43f3a'],
//skin: 'layui-layer-molv', //样式类名 layui-layer-lan layui-layer-molv
closeBtn: 1, //0:不显示;1:窗口里 2:窗口外
icon: 2 //1:成功 2:错误 3:问号 4:锁 5:哭脸 6:笑脸
//shift: 4 //动画类型
});
}
}
});

Action的方法  一般处理程序

context.Response.ContentType = "text/plain";
string json = string.Empty;
try
{
string actionType = context.Request["action"]; //获取动作类型
switch (actionType)
{
case "GetList": //获取数据
json = GetList(context);
break;
case "Add": //添加数据
json = Add(context, "0");
break;
case "Edit": //编辑数据
json = Add(context, "1");
break;
case "Detail": //取得详细
json = Detail(context);
break;
case "Delete": //删除数据
json = Delete(context);
break;

}
context.Response.ContentType = "text/plain";
context.Response.Write(json);
}
catch (Exception e)
{

}

/// <summary>
/// 取得数据
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string GetList(HttpContext context)
{
string pageSize = context.Request["limit"]; //页面大小
string pageBeginIndex = context.Request["offset"]; //当前页起始数据索引
int pageNext = (int.Parse(pageBeginIndex)) / int.Parse(pageSize) + 1; //页码
string name = context.Request["name"];

//string filter = " Title like '%" + name + "%' or Content like '%" + name + "%'";
string filter = " Title like '%" + name + "%'";
int intRecordCount = bll.GetCount(filter);//获取总记录条数
DataSet ds = bll.GetList(int.Parse(pageSize), pageNext, "*", filter, "Orders asc,ID desc");//获取分页数据
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
//string json = new JavaScriptSerializer().Serialize(ds.Tables[0]);
string json = FormatToJson.ToJson(ds.Tables[0]);

return @"{""rows"":" + json + @",""total"":""" + intRecordCount + @"""}";

}
else
{
return @"{""rows"":" + "[]" + @",""total"":""" + 0 + @"""}";
}
}

/// <summary>
/// 取得详细
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string Detail(HttpContext context)
{
JObject jo = new JObject();
string ID = context.Request["ID"];
CCMS.Model.Vote.VoteSubject model = bll.GetModel(int.Parse(ID));

if (model != null)
{
jo.Add("Title", model.Title);
jo.Add("Description", model.Description);
jo.Add("Orders", model.Orders);
jo.Add("Deadline", model.Deadline.ToString("yyyy-MM-dd"));
jo.Add("CreateTime", model.CreateTime);
jo.Add("OpenResult", model.OpenResult);
if (model.IsRestrictIP == true)
{
jo.Add("IsRestrictIP", 1);
}
else
{
jo.Add("IsRestrictIP", 0);
}
jo.Add("Layout", model.Layout);

}
return jo.ToString();
}

/// <summary>
/// 添加或编辑数据
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string Add(HttpContext context, string type)
{
string err = "";
bool result = false;
JObject jo = new JObject();
string ID = context.Request["ID"];
string Tittle = context.Request["Title"];
string content = context.Request["CONTENT"];
string order = context.Request["order"];
string time = context.Request["time"];
string OpenResult = context.Request["OpenResult"];
string IsRestrictIP = context.Request["IsRestrictIP"];
string Layout = context.Request["Layout"];
CCMS.Model.Vote.VoteSubject model = new Model.Vote.VoteSubject();
//添加
if (type == "0")
{
//判断是否已存在
if (bll.GetModelByTitle(Tittle) != null)
{
jo.Add("Status", "0");
jo.Add("Msg", "该投票名称已存在!");
return jo.ToString();
}
if (!string.IsNullOrEmpty(Tittle))
{
model.Title = Tittle;
}
if (!string.IsNullOrEmpty(content))
{
model.Description = content;
}
if (!string.IsNullOrEmpty(order))
{
model.Orders =int.Parse(order);
}
if (!string.IsNullOrEmpty(time))
{
model.Deadline = Convert.ToDateTime(time);
}
if (!string.IsNullOrEmpty(OpenResult))
{
model.OpenResult = int.Parse(OpenResult);
}
if (!string.IsNullOrEmpty(IsRestrictIP))
{
// model.IsRestrictIP = Convert.ToBoolean(IsRestrictIP);
if (IsRestrictIP == "0")
{
model.IsRestrictIP = false;
}
else
{
model.IsRestrictIP = true;
}
}
if (!string.IsNullOrEmpty(Layout))
{
model.Layout = int.Parse(Layout);
}
model.CreateTime = DateTime.Now;

result = bll.Add(model) > 0 ? true : false;
}
//编辑
else
{
model = bll.GetModel(int.Parse(ID));
if (!string.IsNullOrEmpty(Tittle))
{
model.Title = Tittle;
}
if (!string.IsNullOrEmpty(content))
{
model.Description = content;
}
if (!string.IsNullOrEmpty(order))
{
model.Orders = int.Parse(order);
}
if (!string.IsNullOrEmpty(time))
{
model.Deadline = Convert.ToDateTime(time);
}
if (!string.IsNullOrEmpty(OpenResult))
{
model.OpenResult = int.Parse(OpenResult);
}
if (!string.IsNullOrEmpty(IsRestrictIP))
{
if (IsRestrictIP == "0")
{
model.IsRestrictIP = false;
}
else
{
model.IsRestrictIP = true;
}
}
if (!string.IsNullOrEmpty(Layout))
{
model.Layout = int.Parse(Layout);
}
result = bll.Update(model);
}

if (result)
{
jo.Add("Status", "1");
jo.Add("Msg", "保存成功!");
}
else
{
jo.Add("Status", "0");
jo.Add("Msg", "保存失败!");

}

return jo.ToString();

}
/// <summary>
/// 删除
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string Delete(HttpContext context)
{
string err = "";
JObject jo = new JObject();
string id = context.Request["ids"];

bool result = bll.DeleteList(id);

if (result)
{
jo.Add("Status", "1");
jo.Add("Msg", "删除成功!");
}
else
{
jo.Add("Status", "0");
jo.Add("Msg", "删除失败!");
}

return jo.ToString();

}

转载于:https://www.cnblogs.com/xiao-yanzi/p/6283276.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值