时间:2021-07-01 10:21:17 帮助过:8人阅读
string callback = Request["callback"];
string response = string.Format("\"value1\":\"{0}\",\"value2\":\"{1}\", v1, v2);
string call = callback + "({" + response + "})";
Response.Write(call);
客户端
这里使用JQ,有下面两种调用方法:
1、使用getJson
代码如下:
var url = "xxx.aspx?p1=1&p2=2&callback=?";
jQuery.getJSON(url, function(data) {
alert("value1:" + data.value1+ " value2:" + data.value2);
});
2、使用ajax
代码如下:
jQuery.ajax({
type:"get",
url: "xxx.aspx",
dataType : "jsonp",
jsonp: "callback",
data: "p1=1&p2=2&callback=?",
success:function(msg){
alert("value1:" + data.value1+ " value2:" + data.value2);
}
});