标签:
//参考 http://www.cnblogs.com/yuwensong/archive/2013/05/28/3103064.html
后台:
public void ProcessRequest(HttpContext context) { //获取回调函数名 string callback = context.Request.QueryString["callback"]; //json数据 string json = "{\"name\":\"chopper\",\"sex\":\"man\"}"; context.Response.ContentType = "application/json"; //输出:回调函数名(json数据) context.Response.Write(callback + "(" + json + ")"); }
前台:
function fnHello() { $.ajax({ url: "http://172.16.74.102:88/WebAPI/LoginHandller.ashx", dataType: "jsonp", jsonpCallback: "person", data:{aaa:"1111"},//参数后台可以得到 success: function (data) { alert(data.name + " is a a" + data.sex); } }); } //回调函数person function person(data) { alert(data.name + " is a " + data.sex); }
标签:
原文地址:http://www.cnblogs.com/kongxp/p/5674584.html