$.ajax({
type: "GET",
url: "http://localhost:11252/ajax.ashx",//跨域请求的url地址
crossDomain: true,//标记要跨域请求
dataType: "jsonp",//ajax 跨域这里必须这样填写,jsonp是json的扩展
jsonp: "action",//请求处理标注,和jsonpCallback 相对应。
jsonpCallback: "asyncAjax",
data:{"name":"admin"},//要发送的数据信息
success: function (res) { //得到的是json数据,可以是json对象或json数组
alert(res.name);
},
error: function () {
alert("fail");
}
});
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request["action"];// ajax 的jsonp对象值
if (action == "asyncAjax")//ajax 的 jsonpCallback相应值
{
string name = context.Request["name"];
context.Response.Write("asyncAjax" + "({ name:\"" + name + "\"})");//将相应函数名称一起响应,后面跟上可以直接用JavaScript的 eval 解析的json字符串。
}
}
以上是asp.net 前后台的Ajax 跨域请求,如果你能看懂,你就可以解决你提出的问题了。
其他参考:http://www.open-open.com/lib/view/open1334026513327.html
AJAX不支持跨域