客户端:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript" src="/js/jquery/jquery.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: 'http://(serverip)/test/test.aspx',
dataType: "jsonp",
jsonp: "jsonpCallback",
//jsonpCallback="cbcall";
success: function (data) {
alert(data.message);
}
});
});
</script>
</body>
</html>
服务端:/test/test.aspx
protected void Page_Load(object sender, EventArgs e)
{
string jsonCallbak = cls_Fun.CStr(Request["jsonpcallback"]);
string jsondata ="{\"number\":1,\"message\":\"OK\"}";
response.write(jsonCallbak+"("+jsondata+")");
}
说明:
注释行://jsonpCallback="cbcall";可以省略,去掉注释代码更加简洁。