ajax请求类库
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.SessionState;
namespace JsonFactory
{
public class JsonHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get { return false;
}
}
public void ProcessRequest(HttpContext context)
{
context.Response.Cache.SetExpires(DateTime.Now);
context.Response.ContentType = jsonType;
this.SetResponse(context);
context.Response.End();
}
private const string jsonType = "application/json";
private const string javascriptType = "application/javascript";
private void SetResponse(HttpContext context)
{
string[] segments = context.Request.Url.Segments;
string action = "";
if (segments.Length < 3)
{
return;
}
action = segments[2].Trim('/').ToLower();
JsonBase json = null;
switch (action)
{
case "user":
json = new InformationJsonData(context.Request);
break;
default:
break;
}
if (json == null)
{
return;
}
string responseString = json.OutputData();
//var compress = new PageCompression(context);
//compress.GZipEncodePage();
context.Response.Write(responseString);
}
}
}
ajax请求类似路由API(MVC):
【ajax请求类库】 //API路由
var formatters = GlobalConfiguration.Configuration.Formatters;
formatters.Remove(formatters.XmlFormatter);
System.Web.Routing.RouteTable.Routes.MapHttpRoute("DefaultAPi",
"api/{controller}/{action}/{id}",
new { id = RouteParameter.Optional });
public class MyController : ApiController
{
///
/// 获取单个出团日期日期数据
///
///
///
[AcceptVerbs("POST", "GET")]
public string GetHelloWorld(int id)
{
return "hello world" + id;
}
$(function () {
/*
$.post("/Json/Information/admin", function (d) {
alert(d);
});
*/
var id = 1;
$.post("/API/My/GetHelloWorld/" + id, function (d) {
alert(d);
});
})
}
转载于:https://www.cnblogs.com/wangyhua/p/4050592.html
推荐阅读
- thinkphp|thinkphp 3.2 如何调用第三方类库
- https请求被提早撤回
- 遇到不正当请求怎么办
- 使用Promise对微信小程序wx.request请求方法进行封装
- AnyProxy抓取http/https请求
- JavaScript|vue 基于axios封装request接口请求——request.js文件
- spring|spring boot中设置异步请求默认使用的线程池
- c#常用网址记录
- 微信小程序请求接口格式
- http请求与响应