ashx 文件的使用
它就类似.aspx文件,用于处理传入到服务器的HTTP请求,但它不会像.aspx文件那样要返回处理结果和大量HTML,它可以返回简单的字符串、图片等。
百度百科定义链接:http://baike.baidu.com/view/3799515.htm
开发实例如下:
前端请求核心代码(json):
var jsonArray= new Array();
var jsonObj = {};
jsonObj["CourseId"] = $(this).children().eq(0).text();;
jsonObj["CertCategory"] = $(this).children().eq(3).text();
jsonObj["SubCertCategory"] = $(this).children().eq(4).text();
jsonArray.push(jsonObj)
});
var jsonDate =
{
jsontype: "objType",
jsonCount: jsonArray.length,
jsonArray: jsonArray
}
$.ajax({
type: "post",
url: "/AjaxPage/Certification.ashx",
dataType: "json",
data: objDate,
complete :function(){$("#load").hide();},//AJAX请求完成时隐藏
success: function (data)
{
if (data["Succeed"])
{
alert("提交成功!");
window.location.href = “";
}
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert("请求对象XMLHttpRequest: "+XMLHttpRequest);
alert("错误类型textStatus: "+textStatus);
alert("异常对象errorThrown: "+errorThrown);
}
});
后台ashx 接收:
public void ProcessRequest(HttpContext context)
{
string jsontype= context.Request["jsontype"];
int certCount=context.Request["jsonCount"];
AjaxResult result = new AjaxResult ();
switch (jsontype)
{
case "objType":
{
#region 操作
for (int k = 0; k < certCount; k++)
{
var courseId = context.Request["jsonArray[" + k + "][CourseId]"];
}
result.Succeed = true;
result.resultMsg= ex.Message;
context.Response.Write(JsonConvert.SerializeObject(result));
}
break;
#endregion
}
}
返回信息构建:
public class AjaxResult {
public bool Succeed { get; set; }
public string resultMsg { get; set; }
public object ObjInfo { get; set; }
public void setTrue(string message)
{
this.Succeed = true;
this.resultMsg= message;
}
public void setError(string message)
{
this.Succeed = false;
this.resultMsg= message;
}
}
ashx 文件的使用的更多相关文章
- .NET .ashx 文件 用Session 是需要注意的问题
.ashx 文件,默认不可使用 Session ,需要使用Session 时, 需要引用 接口 IRequiresSessionState 例如: public class AddHouseInfo ...
- ashx文件不能使用DAL和Model的解决办法
好久没有写web程序了,今天在写web程序时,发现一个问题,在ashx文件中,已经using了DAL和Model命名空间,而且引用中也引用了程序集,可是还报错:未能找到类型或命名空间"Mod ...
- Ajax跨域请求ashx文件与Webservice文件
前台页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...
- 在Handler.ashx文件中使用session
使用jquery调用handler文件中的方法,需要使用session,默认生成的文件中,不可以直接使用session.按照以下步骤,即可以通过session与其他的aspx页面的session进行数 ...
- ASP.NET的SEO:使用.ashx文件——排除重复内容
本系列目录 不同的链接指向的页面如果具有大量相同的内容,这种现象就会被称为"重复内容",如果一个网站的重复内容很多,搜索引擎就会认为这个网站的价值不高.所以我们应尽量避免各种重复内 ...
- ashx文件要使用Session
ashx文件要使用Session,必须实现Session接口; using System;using System.Web;using System.Web.SessionState; //第一步:导 ...
- 解决ashx文件下的Session“未将对象引用设置到对象的实例”
using System; using System.Collections.Generic; using System.Linq; using System.Web; using PPT_DAL; ...
- 创建安全的ashx文件,ashx编译
<%@ WebHandler Language="C#" Class="Handler2" %> using System; using Syste ...
- ashx文件结合ajax使用(返回json数据)
ashx文件返回json数据: public void ProcessRequest(HttpContext context) { context.Response.ContentType = &qu ...
- ashx文件的使用
转自:http://www.cnblogs.com/Tally/archive/2013/02/19/2916499.html ashx是什么文件 .ashx 文件用于写web handler的..a ...
随机推荐
- JDBC插入数据时中文变为问号的解决方法
JDBC插入数据时中文变为问号的解决方法 制作人:全心全意 出现中文变问号的代码: String url = "jdbc:mysql://localhost:3306/test"; ...
- Datatable 导出到execl 官网demo
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...
- 爬虫——使用ItemLoader维护item
在item的Filed()中设置参数函数,可以用来预处理item字段的数据,另一方面也方便程序代码的管理和重用 item中 from scrapy.loader.processors import M ...
- tyvj1117 拯救ice-cream
背景 天好热……Tina顶着那炎炎的烈日,向Ice-cream home走去……可是……停电了……冰淇淋们躺在Ice-cream home的冰柜里,慢慢地……慢慢地……融化…………你说,她能赶在冰 ...
- Nth Largest Value
Problem Description For this problem, you will write a program that prints the Nth largest value in ...
- HDU——1787 GCD Again
题意: 在一次acm竞赛之后,你花了一些时间去思考和尝试解决那些未解决的问题吗? 不知道?哦,当你想成为“大牛”的时候,你就必须这样做. 现在你会发现,这个问题是如此熟悉: 两个正整数a和b的最大GC ...
- 在Electron中通过ffi模块实现JavaScript调用C++动态库
目前在网上能搜到的JS调C++动态库的实现有两种,一种是通过开发Node.js addon模块的方式实现调用,这种对于我们已有的代码实现比较复杂,需要大量的开发,因此不适用:另一种是通过FFI模块,F ...
- AWR and ADDM
The Automatic Workload Repository Oracle collect a vast amount of statistics regarding the performan ...
- Jsp中EL表达式的使用
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 1.什么是EL EL是JSP表达式语言,全称是ExpressionLang ...
- 百度LBS云搜索时报错 "filter:area is not filteable field, please set property in the cloud-storage
{"status":2,"message":"filter:area is not filteable field, please set prope ...