简单的jsonp

2018-04-27  本文已影响0人  刘学_b270

//服务器端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) }
);

上一篇下一篇

猜你喜欢

热点阅读