ajax的异步请求,简单方便的更改页面上想要显示的值,无刷新页面
如一楼,二楼所述,用法比较灵活
ashx是继承IHttpHander接口,我们一般开发的aspx页面的基类Page也是继承IHttpHander,你可以把ashx想象成一个没有任何控件,没有任何页面那些事件的的aspx页面
一般地讲,aspx页面是一种特殊的ashx,它比ashx多了控件的生成,页面事件等,所以,如果需要效率高的话,考虑ashx
HttpRequest gRequest = null;
HttpContext gContext = null;
HttpResponse gResponse = null;
string func = string.Empty;
string result = string.Empty;
string pageUrl = string.Empty;
string loginUserId = string.Empty;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
gContext = context;
gRequest = context.Request;
gResponse = context.Response;
pageUrl = gRequest.UrlReferrer.AbsolutePath;
func = gRequest["func"];
loginUserId = Common.CheckUserState.GetLoginUserId();
MethodInfo method = typeof(BriefReason).GetMethod(func);
if (method != null)
{
object[] args = new object[] { result };
method.Invoke(this, args);
result = (string)args[0];
gResponse.Write(result);
}
}
public void IsExistsStock(out string result)
{
result = "-1";
var sotckcode = gRequest["stockcode"];
string sql = "select count(1) from BriefReason where StockCode='" + sotckcode + "'";
BLL.BriefReason bll = new BLL.BriefReason();
object rs = bll.ExecuteScalar(sql);
result = rs.ToString();
}
通过反射直接调用吧,前端直接写方法名称就可以了func=你的方法
$.post("../Ashx/BriefReason.ashx?func=IsExistsStock", { stockcode: stockcode }, function (msg) {
if (msg >= 1) {
$.messager.alert("系统提示", "已存在该个股,请修改数据或添加新的个股!", "error");
$("#btnSave").attr("disabled", true);
} else {
$("#btnSave").removeAttr("disabled");
}
});
用于处理数据,Jquery+ashx来异步Ajax,
公共方法....