data.jsonp = function (url,jsonpParam, data, async, successfn, errorfn) {
$.ajax({
url: url,
jsonp: jsonpParam,
type: "get",
dataType: "jsonp",
async: async,
data: data,
success: function (result) {
successfn(result);
},
error: function (e) {
errorfn(e);
}
});
}
后台
protected void Page_Load(object sender, EventArgs e)
{
string callback = Request["callback"];
string txt = Server.UrlDecode(Request["txt"]);
Code.Helper helper = new Code.Helper();
string path = helper.CreateMap3(txt);
string json = "{\"result\":\"" + path + "\"}";
string result = callback + "(" + json + ")";
Response.Write(result);
}
注: jsonp 请求中的 jsonpParam 前端和后端 参数名要一致 (就是 callback)