简单的jsonp

//服务器端ashx
public class Handler2 : IHttpHandler {

public void ProcessRequest (HttpContext context) {
    HttpRequest Request = HttpContext.Current.Request;
    string callback = Request.QueryString["callback"];

    string name = Request.QueryString["name"];

    context.Response.Write(callback + "({msg:'this is"+name+"jsonp'})");
}

public bool IsReusable {
    get {
        return false;
    }
}

}

//script
$.getJSON(
"http://localhost:63124/Handler.ashx?callback=?",
{ name: "ff", time: "2pm" },
function(data) { alert(data.msg) }
);

你可能感兴趣的:(简单的jsonp)