62,074
社区成员
发帖
与我相关
我的任务
分享
window.onload = function() {
$.ajax({
type: "POST",
url: "GetJsonMethod.ashx",
dataType: 'json',
success: function(res) {
alert(res);
var h = "<table>";
$(data["FirstJson"]).each(function(i, user) { h += "<tr><td>ID:" + user.Pro_ID + "</td><td>名称:" + user.Pro_Name + "</td></tr>"; });
h += "</table>";
$("#divResult").html(h);
},
error: function(res, text) {
alert(text);
}
});
}
string str = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];//连接字串
System.Data.DataSet ds;//dataset
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(@"Data Source=***");
con.Open();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select top 10 Pro_ID,Pro_Name from YXShop_Product", con);
System.Data.SqlClient.SqlDataAdapter adapt = new System.Data.SqlClient.SqlDataAdapter(cmd);
ds = new System.Data.DataSet();
adapt.Fill(ds);
string result = Json.DataTableToJSON(ds.Tables[0], "FirstJson");
//result = "{success:true,data:" + result + "}";
Response.Write(result);
Response.End();
context.Response.ContentType = "text/plain";
context.Response.Write("[{\"m_Status\":16800000}]");
//这样httpHandler只会处理Config文件中的 ashx
<add verb="*" path="Config/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
{"FirstJson":[{"Pro_ID":"536","Pro_Name":"十全十美 - 钻石耳坠"},{"Pro_ID":"593","Pro_Name":"魔法情缘--钻石吊坠"}, {"Pro_ID":"7225","Pro_Name":"珍贝--钻石戒指"},{"Pro_ID":"7226","Pro_Name":"围绕 --钻石戒指"},{"Pro_ID":"7227","Pro_Name":"心花盛放--钻石戒指"}, {"Pro_ID":"7228","Pro_Name":"魔力--钻石戒指"},{"Pro_ID":"7229","Pro_Name":"星雨 --钻石戒指"},{"Pro_ID":"7230","Pro_Name":"花魁--钻石戒指"}, {"Pro_ID":"7231","Pro_Name":"守护之心--钻石戒指"},{"Pro_ID":"7232","Pro_Name":"夺目--钻石戒指"}]}