using System
using System.Web
using System.Net
public class Home : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain"
object type = context.Request.Params["type"]
string jsonpCallback = context.Request.Params["jsonpCallback"]
if (type == null||type.ToString()=="")
{
context.Response.Write("type is null")
}else {
switch (type.ToString()) {
case "login":
//.....
break
}
}
}
public bool IsReusable {
get {
return false
}
}
} jsonp跨域请求
$.ajax({
type: "get",
url: "Ashx/login/login.ashx",
dataType: 'jsonp',
jsonp: "jsonpCallback",
data: params,
success: function (result) {
//正常返回数据的处理
}, error: function (XMLHttpRequest, textStatus, errorThrown) {
//请求错误时处理
}
})
非跨域请求:
$.get("Ashx/login/login.ashx",{"参数":"如果木有可以为空"},function(result){
//正常请求返回的数据(无法扑捉到error信息)
})
最近刚好在写这个...
如果还不明白,就问