码迷,mamicode.com
首页 > Web开发 > 详细

ajax+ashx

时间:2015-02-09 15:52:52      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

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";
}

 

ajax+ashx

标签:

原文地址:http://www.cnblogs.com/sunzgod/p/4281426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!