這是我在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)\/\」}]「}
而結果是沒有任何內容。加載「閃爍,然後它返回空白頁..請幫助我顯示這裏的問題是..謝謝很多。
這是如此偉大..謝謝這麼多@無.. –