服務器端 復制代碼 代碼如下:
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);
}
});