南强小屋 Design By 杰米

.ashx 文件用于写web handler的。.ashx文件与.aspx文件类似,可以通过它来调用HttpHandler类,它免去了普通.aspx页面的控件解析以及页面处理的过程。其实就是带HTML和C#的混合文件。

.ashx文件适合产生供浏览器处理的、不需要回发处理的数据格式,例如用于生成动态图片、动态文本等内容。很多需要用到此种处理方式。此文档提供一个简单的调用ashx文件的Demo,并贴出关键文件的源码。

以下为Demo中Login.ashx文件中的源码:

public class Login : IHttpHandler { 

public void ProcessRequest (HttpContext context) { 
context.Response.ContentType = "application/json"; 
//GET方式获取传递的数据 
//string username = context.Request.QueryString["username"]; 
//string password = context.Request.QueryString["password"]; 

//POST方式获取传递的数据 
string username = context.Request.Form["username"]; 
string password = context.Request.Form["password"]; 
string message = null; 
if (string.IsNullOrEmpty(username)) 
{ 
message = "用户名不能为空"; 
context.Response.Write("{\"success\":false,\"message\":\"" + message + "\"}");//此JSON格式非常重要,否则会执行jquery的的error函数 
context.Response.End(); 
} 
if (string.IsNullOrEmpty(password)) 
{ 
message = "密码不能为空"; 
context.Response.Write("{\"success\":false,\"message\":\"" + message + "\"}"); 
context.Response.End(); 
} 
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) 
{ 
if (username.ToUpper() == "ADMIN" && password == "123") 
{ 
message = "登录成功"; 
context.Response.Write("{\"success\":true,\"message\":\"" + message + "\"}"); 
} 
else 
{ 
message = "用户名或密码错误"; 
context.Response.Write("{\"success\":false,\"message\":\"" + message + "\"}"); 
} 
} 
context.Response.End(); 

} 

public bool IsReusable { 
get { 
return false; 
} 
} 
}

以下为html中的源码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>jsquery访问ashx文件</title> 
<script language="javascript" type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.4.1.min.js">
标签:
jquery,ashx

南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米

评论“jquery访问ashx文件示例代码”

暂无jquery访问ashx文件示例代码的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。