提交FCKeditor编辑的内容后保存到数据库.然后用$.getJSON 来显示到页面上来.
我查了输出的JSON格式是正确的.但是就显示不到界面上来.
为什么前台代码 function getData(){
$("#list").html("");//清空列表中的数据
//发送ajax请求
$.getJSON("Aritle.ashx", function(json){
$.each(json,function (i){
$("#Context").html(json[i].Context);
}
);
});
}
</script>后台ashx代码 context.Response.ContentType = "text/plain";
context.Response.Buffer = true;
DataSet dset = SQLServerDAL.Query("Select * from Aritcle where ID =7");
if (dset != null)
{
WriteText= Utility.DtToSON(dset.Tables[0]);
}
context.Response.Write(WriteText);DtToSON 代码 public static string DtToSON(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("[");
for (int i = 0; i < dt.Rows.Count; i++)
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"");
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("\":\"");
jsonBuilder.Append(HtmlDecode(dt.Rows[i][j].ToString()));
jsonBuilder.Append("\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
return jsonBuilder.ToString();
}
我查了输出的JSON格式是正确的.但是就显示不到界面上来.
为什么前台代码 function getData(){
$("#list").html("");//清空列表中的数据
//发送ajax请求
$.getJSON("Aritle.ashx", function(json){
$.each(json,function (i){
$("#Context").html(json[i].Context);
}
);
});
}
</script>后台ashx代码 context.Response.ContentType = "text/plain";
context.Response.Buffer = true;
DataSet dset = SQLServerDAL.Query("Select * from Aritcle where ID =7");
if (dset != null)
{
WriteText= Utility.DtToSON(dset.Tables[0]);
}
context.Response.Write(WriteText);DtToSON 代码 public static string DtToSON(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("[");
for (int i = 0; i < dt.Rows.Count; i++)
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"");
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("\":\"");
jsonBuilder.Append(HtmlDecode(dt.Rows[i][j].ToString()));
jsonBuilder.Append("\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
return jsonBuilder.ToString();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货