1.请求页面:
$.ajax({
url: "http://localhost:4474/LanCheng/HZ_FY/hz_fyys/ystz_Ajax.ashx?callback=callback",
dataType: 'jsonp',
data: "{}",
jsonp: "callback",
success: function (result) {
result = JSON.parse(result);
for (var i in result) {
alert(i + ":" + result[i].cuserName);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
2.一般处理程序:
public void ProcessRequest(HttpContext context)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
context.Response.ContentType = "text/plain";
//返回Json数据集
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT id,cuserName,cpassword FROM dbo.hz_com_user WHERE id IN(26403,26168)");
DataTable dtData = Sys.ExecuteToTable(strSql.ToString());
context.Response.Write(JsonHelper.JSONHelper.DataTableToJSON(dtData));
context.Response.End();
}
页面信息: