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 ...
随机推荐
- Liunx学习笔记(三) 文件权限
一.文件权限 1.查看文件权限 (1)文件权限 在 Linux 中对于文件有四种访问权限,列举如下: 可读取:r,Readable 可写入:w,Writable 可执行:x,Execute 无权限:- ...
- scrapy 按顺序抓取text内容
需求:获得如下li.clearfix 下的所有text,并且按顺序输出 1. x.css('div.reply-doc h4 a::text').extract(); 2. x.css('div.r ...
- Linux命令介绍
资料链接:(Linux基本命令介绍)http://note.youdao.com/share/?id=36c07917f8d3e6437c1e764c3516a3f2&type=note#/ ...
- 【Codeforces 264B】Good Sequences
[链接] 我是链接,点我呀:) [题意] 让你在一个递增数组中选择一个最长子序列使得gcd(a[i],a[i+1])>1 [题解] 设f[i]表示以一个"含有素因子i的数字" ...
- Contemplation! Algebra 矩阵快速幂
Given the value of a+b and ab you will have to find the value of a n + b n Input The input file cont ...
- MySQL语句给字段值加1
update tbl_moment_like set like_count = like_count + #{addLikes} where mid = #{mid}
- 通过DaoCloud发布Ghost
首先参考这篇文章: http://docs-static.daocloud.io/daocloud-services/volume-controller 但是按照这篇文章,最后的主题是没有办法应用上去 ...
- Clojure: 寻找项目依赖项目
Clojure寻找项目依赖项目: lein deps :tree
- git 手动操作
git 手动操作 以下所有的情况都需要在上面那个目录下: 查看改动: git status // 所有改动都在这里. 提交代码: git add <file_name> // 把代码放到 ...
- win7下登入本機、域的正確方法
win7的登入与以前的windows系统有所不同,如果win7的电脑已经被加入到域後,登入有两种类别: 1: 要登入到域,直接输入域用户账号和密码. 2:要登入到本机,则要输入计算机名\本机用户账号和 ...