<script type="text/javascript">
$(function () {
$.post("ajax/getData.ashx", function (serverdata) {
//alert(serverdata);
var Djson = jQuery.parseJSON(serverdata);
var ArticleTitle = Djson["ArticleTitles"];
var html = "";
$(ArticleTitle).each(function () {
html += "<tr>"+"<td>" + this.OrderNum + "</td>"+"<td>" + this.CustName + "</td>"+"<td>" + this.CustID + "</td>"+"<td>" + this.PartNum + "</td>"+"<td>" + this.PartDescription + "</td>"+"</tr>"
});
$("#Th").html(html);
});
});
</script>
HTML:
Ajax:
try
{
DataTable dt = Abos.BGetTb();
JsonSerializerSettings Setting = new JsonSerializerSettings();
Setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
string result = JsonConvert.SerializeObject(new { ArticleTitles = dt }, Formatting.Indented, Setting);
context.Response.Write(result);
}
catch (Exception ex) { throw ex; }
}
这里最主要的是:
引用:using Newtonsoft.Json;
获取DataTable数据以后的三段序列化DataTable为JSON的代码。
如果没有
Newtonsoft.Json引用可以去网上下载。
效果: