ajax+ashx

eg:

$(‘.setIsEnableClosed‘).click(function(){

var id=$(id).attr("name");

var isChecked=$(this).prop("checked");

$.ajax({

url:"../../ashx/Widget.ashx",

data:{‘type‘:‘setEnableClose‘,‘id‘:id,‘isChecked‘:isChecked},

cache:false,

success:function(result){

  if(result==‘true‘)

    success("设置成功!");

  else if(data=‘sessionOut‘){

    warning(‘登录超期,将跳转至登录界面!‘,function(){

    setTimeout(‘window.location.href="../../login.aspx",3000‘);

  });

  }

  else

    warning("设置失败,请联系管理员");

},

  error:function(){

  danger("设置出错,请联系管理员");  

}

})

})

 

 

.ashx :

 

public void ProcessRequest(HttpContext context)

{

_currentUser=contenxt.Session[SystemConfig.Account_Key] as Domin.Exchange.User;

if(_currentUser==null)

{

  content.response.Write("sessionOut");

  return;

}

 

var type=context.Requset["type"];

if(type.IsNullorEmpty())

return;

var result = Process(type, context);

if (result != null) {
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
context.Response.Write(result);
}

 

 private string Process(string type, HttpContext context)

{

_addOn = context.Request["addOn"];

switch (type) {
case "save":
return SaveWidgetInfo(context);
case "setAuthorize":
return SetAuthorize(context);
case "reset":
return Reset();
case "setEnableClose":
return SetIsEnableClose(context);
default:
return null;

}


/// <summary>
/// 设置部件是否允许删除
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string SetIsEnableClose(HttpContext context)
{
var id = context.Request["id"].ToInt32();

if (id < 0)
return "false";
var isChecked = context.Request["isChecked"];
bool isEnableClose=isChecked.ToBoolean();
var data = _widgetAuthorize.Get(id);
if (data != null && data.IsEnableClose!= isEnableClose)
{
data.IsEnableClose = isEnableClose;
_widgetAuthorize.Update(data);
}
return "true";
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。