这是我在Default.aspx的代码:无法从方法的getJSON获取数据
$(function() {
var dataSource = {};
$("#MainTree,#SubTree").jstree({
"json_data": {
"ajax":{
type: "POST",
async: true,
url: "Default.aspx/GetJson",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function(msg) {
dataSource = msg;
},
error: function(err) {
alert(err);
},
data: dataSource,
},
},
"plugins": ["themes", "json_data", "ui", "dnd"]
});
});
这里是的getJSON方法Default.aspx.cs:
[WebGet(ResponseFormat = WebMessageFormat.Json)]
[System.Web.Services.WebMethod]
public static string GetJson()
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
DataTable dtEmployee = new DataTable();
dtEmployee.Columns.Add("EmpId", typeof(int));
dtEmployee.Columns.Add("Name", typeof(string));
dtEmployee.Columns.Add("Address", typeof(string));
dtEmployee.Columns.Add("Date", typeof(DateTime));
//
// Here we add five DataRows.
//
dtEmployee.Rows.Add(25, "Rk", "Gurgaon", DateTime.Now);
dtEmployee.Rows.Add(50, "Sachin", "Noida", DateTime.Now);
dtEmployee.Rows.Add(10, "Nitin", "Noida", DateTime.Now);
dtEmployee.Rows.Add(21, "Aditya", "Meerut", DateTime.Now);
dtEmployee.Rows.Add(100, "Mohan", "Banglore", DateTime.Now);
foreach (DataRow dr in dtEmployee.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dtEmployee.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
编辑: 这是我检查GetJson方法响应的结果: {“d”:“[{\”EmpId \“:25,\”Name \“:\”Rk \“,\”Address \“:\”Gurgaon \“ ,\ “日期\”:\ “\ /日期(1372999726975)\/\”},{\ “EMPID \”:50,\ “名称\”:\ “萨钦\”,\ “地址\”:\”诺伊达\”,\ “日期\”:\ “\ /日期(1372999726975)\/\”},{\ “EMPID \”:10 \ “名称\”:\ “尼廷\”,\ “地址\” :\ “诺伊达\”,\ “日期\”:\ “\ /日期(1372999726975)\/\”},{\ “EMPID \”:21 \ “名称\”:\ “阿迪亚\”,\“地址\ “:\” 密拉特\”,\ “日期\”:\ “\ /日期(1372999726975)\/\”},{\ “EMPID \”:100,\ “名称\”:\ “磨憨\”,\ “Address \”:\“Banglore \”,\“Date \”:\“\/Date(1372999726975)\/\”}]“}
而结果是没有任何内容。加载“闪烁,然后它返回空白页..请帮助我显示这里的问题是..谢谢很多。
这是如此伟大..谢谢这么多@无.. –