1.什么是跨域请求:
服务器A上的一个页面,要请求服务器B上的一个处理程序,这就叫做跨域请求
本次的测试页面为:
处理程序kimhandler.ashx,如下:
%@ WebHandler Language="C#" Class="KimHandler" %>
using System;
using System.Web;
public class KimHandler : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
string msg = "{"name":"kim","gender":"男","age":24}";
context.Response.Write(msg);
}
public bool IsReusable {
get {
return false;
}
}
}
另一张处理程序handler.ashx如下:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
string callbackName = context.Request.Params["callbackFun"];
string msg = callbackName+ "({"name":"kim","age":"18"});";
context.Response.Write(msg);
}
public bool IsReusable {
get {
return false;
}
}
}
2.Ajax无法实现跨域请求


