它就类似.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 文件的使用的更多相关文章

  1. .NET .ashx 文件 用Session 是需要注意的问题

    .ashx 文件,默认不可使用 Session ,需要使用Session 时, 需要引用 接口 IRequiresSessionState 例如:  public class AddHouseInfo ...

  2. ashx文件不能使用DAL和Model的解决办法

    好久没有写web程序了,今天在写web程序时,发现一个问题,在ashx文件中,已经using了DAL和Model命名空间,而且引用中也引用了程序集,可是还报错:未能找到类型或命名空间"Mod ...

  3. Ajax跨域请求ashx文件与Webservice文件

    前台页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...

  4. 在Handler.ashx文件中使用session

    使用jquery调用handler文件中的方法,需要使用session,默认生成的文件中,不可以直接使用session.按照以下步骤,即可以通过session与其他的aspx页面的session进行数 ...

  5. ASP.NET的SEO:使用.ashx文件——排除重复内容

    本系列目录 不同的链接指向的页面如果具有大量相同的内容,这种现象就会被称为"重复内容",如果一个网站的重复内容很多,搜索引擎就会认为这个网站的价值不高.所以我们应尽量避免各种重复内 ...

  6. ashx文件要使用Session

    ashx文件要使用Session,必须实现Session接口; using System;using System.Web;using System.Web.SessionState; //第一步:导 ...

  7. 解决ashx文件下的Session“未将对象引用设置到对象的实例”

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using PPT_DAL; ...

  8. 创建安全的ashx文件,ashx编译

    <%@ WebHandler Language="C#" Class="Handler2" %> using System; using Syste ...

  9. ashx文件结合ajax使用(返回json数据)

    ashx文件返回json数据: public void ProcessRequest(HttpContext context) { context.Response.ContentType = &qu ...

  10. ashx文件的使用

    转自:http://www.cnblogs.com/Tally/archive/2013/02/19/2916499.html ashx是什么文件 .ashx 文件用于写web handler的..a ...

随机推荐

  1. save density, pressure, velocity, temperature contour at one slice in xy plane-- paraview with batch Python scripts

    #### import the simple module from the paraviewfrom paraview.simple import *#### disable automatic c ...

  2. 高德地图将字符串地址转为经纬度的一个demo

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...

  3. 【Codeforces 1009C】Annoying Present

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实就是让你最后这n个数字的和最大. 加上的x没有关系.因为肯定都是加上n个x 所以直接加上就可以了 主要在于如何选取j 显然我们要找到一个位 ...

  4. [bzoj2055]80人环游世界[网络流,上下界网络流]

    手动画了整张图,,算是搞懂了吧,, #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; templat ...

  5. rest frame work纪念版代码

    models.py from django.db import models from pygments.lexers import get_all_lexers from pygments.styl ...

  6. Ubuntu 16.04通过Trickle限制某个软件的下载/上传速度

    在Linux下没有Windows使用360那样去限制某个软件的速度. 但是通过Trickle可以设置某个软件的网速,但是前提是通过Trickle命令连带启动这个软件才可以,不能中途去设置. 比如现在很 ...

  7. Windows Server下把BAT批处理注册成服务在后台运行且注销后能正常运行

    批处理有如下特点: 1.登录到当前窗口运行时,如果关闭控制台会连同启动的程序一起关闭. 2.如果是以start /b的形式启动,那么同样也是在控制台关闭后者注销当前窗口也会一起关闭. 3.如果以vbs ...

  8. dubbo bug之 Please check registry access list (whitelist/blacklist)的分析与解决

    1.基本就是dubbo provider没有启动会造成这种情况. 2.api和service是同一个项目,并不是俩项目. 通过启动api,run on server是不能启动service的,必须通过 ...

  9. 配置 Profile Manager(2)

    五.配置登录用户 点开"账户->用户"页面,创建1个管理员: 创建 1 个普通用户: 六.启用 MDM 选择"服务->描写叙述文件管理器".将 sw ...

  10. 【JAVA】两点经纬度直线距离的计算

    来自谷歌地图的计算公式: 通过JAVA的Math类各种方法调用.实现上述公式 private static double EARTH_RADIUS = 6378.137;// 单位千米 /** * 角 ...