ajax 与 ashx交互
2020-07-25 13:07 idea555 阅读(219) 评论(0) 收藏 举报<script src="Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "post", //提交方式
url: "/ashx/FZGpyShowData.ashx", //一般处理程序的路径
data: { corpName: "xiong" }, //向后台传入的值
dataType: "json", //返回值格式
success: function (data) { //返回成功后将要做的事,这里是返回一个表
alert(data.key3);
}
});
})
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebFrom.ashx
{
/// <summary>
/// FZGpyShowData 的摘要说明
/// </summary>
public class FZGpyShowData : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string corpName = context.Request["corpName"].Trim().ToString(); //接收前台传过来的参数
if(!string.IsNullOrEmpty(corpName))
{
}
string key3 = "aaa555";
string key4 = "bbb";
string resStr = "{\"key3\":\"" + key3 + "\", \"key4\":\"" + key4 + "\"}";
context.Response.Write(resStr);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
浙公网安备 33010602011771号