1

这是我的代码:

var data = "";
    $(function() {
        $("#MainTree,#SubTree").jstree({
            "json_data": {
                "data": data,
                "ajax":{
                    type: "POST",
                    async: true,
                    url: "Default.aspx/GetJson",
                    contentType: "application/json; charset=utf-8",
                    //data: '{name:""}',
                    dataType: "json",
                    cache: false,
                    success: function(msg) {
                         data = msg;

                    },
                    error: function(err) {
                        alert(err);
                    }
                },

            },
            "plugins": ["themes", "json_data", "ui", "dnd"]
        });
    });

这是我的 GetJson 方法:

[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);
}    

在我的 Default.aspx.cs 中,我创建了一个名为 GetJson 的方法,当我运行此代码时,它返回了警报(错误)。请帮我看看发生了什么?

已编辑:当我在浏览器中检查时,该方法获得状态代码 200 OK,但在响应中..它向我显示页面 Default.aspx(context html)

4

0 回答 0