Javascript jsTree未激发Webmethod

Javascript jsTree未激发Webmethod,javascript,jstree,jstree-search,Javascript,Jstree,Jstree Search,我试图从jsTree调用web方法,但无法调用它。有人能帮我解决这个问题吗 我的jsTree函数是:- $('#tree').jstree({ "json_data": { "ajax": { "type": "POST", "dataType": "json", "async": true, "contentType": "application/json;",

我试图从jsTree调用web方法,但无法调用它。有人能帮我解决这个问题吗

我的jsTree函数是:-

 $('#tree').jstree({
    "json_data": {
        "ajax": {
            "type": "POST",
            "dataType": "json",
            "async": true,
            "contentType": "application/json;",
            "opts": {
                "method": "POST",
                "url": "../../SurveyReport/Metrics.aspx/GetAllNodes11"
            },
            "url": "../../SurveyReport/Metrics.aspx/GetAllNodes11",
            "data": function (node) {
                if (node == -1) {
                    return '{ "operation" : "get_children", "id" : -1 }';
                }
                else {
                    //get the children for this node
                    return '{ "operation" : "get_children", "id" : ' + $(node).attr("id") + ' }';
                }
            },
            "success": function (retval) {
                alert('Success')
                return retval.d;
            },
            "error": function (r) {
                alert(r.attr);
                alert('error');
            }
        }
    },
    "plugins": ["themes", "json_data"]
});
web方法和数据文件为:-

 [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<G_JSTree> GetAllNodes11(string id)
{
    if (id != "-1") //-1 means initial load else async loading of children
    {
        if (id == "10")
            //Add 3 children to parent node with id=10.
            return AddChildNodes(10, 3, "xxxx");
        else
            return new List<G_JSTree>();
    }
    List<G_JSTree> G_JSTreeArray = new List<G_JSTree>();

    //Creating the JsTree data
    //In live scenarios this will come from db or Web Service
    //Add 5 root nodes
    G_JSTreeArray.AddRange(AddChildNodes(0, 5, ""));

    //Add 4 children to 3rd root node
    //The third node has id=30
    //The child nodes will have ids like 301,302,303,304
    G_JSTreeArray[3].children = (AddChildNodes(30, 4, G_JSTreeArray[3].data)).ToArray();

    //Add 5 children to level1 Node at id=302
    G_JSTreeArray[3].children[1].children = (AddChildNodes(302, 4, G_JSTreeArray[3].children[1].data)).ToArray();

    return G_JSTreeArray;
}


private static List<G_JSTree> AddChildNodes(int _ParentID, int NumOfChildren, string ParentName)
{
    List<G_JSTree> G_JSTreeArray = new List<G_JSTree>();
    int n = 10;
    for (int i = 0; i < NumOfChildren; i++)
    {
        int CurrChildId = (_ParentID == 0) ? n : ((_ParentID * 10) + i);
        G_JSTree _G_JSTree = new G_JSTree();
        _G_JSTree.data = (_ParentID == 0) ? "root" + "-Child" + i.ToString() : ParentName + CurrChildId.ToString() + i.ToString();
        _G_JSTree.state = "closed";  //For async to work
        _G_JSTree.IdServerUse = CurrChildId;
        _G_JSTree.children = null;
        _G_JSTree.attr = new G_JsTreeAttribute { id = CurrChildId.ToString(), selected = false };
        G_JSTreeArray.Add(_G_JSTree);
        n = n + 10;
    }
    return G_JSTreeArray;
}

public class G_JSTree
{
    public G_JsTreeAttribute attr;
    public G_JSTree[] children;
    public string data
    {
        get;
        set;
    }
    public int IdServerUse
    {
        get;
        set;
    }
    public string icons
    {
        get;
        set;
    }
    public string state
    {
        get;
        set;
    }
}

public class G_JsTreeAttribute
{
    public string id;
    public bool selected;
}
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
公共静态列表GetAllNodes11(字符串id)
{
if(id!=“-1”)/-1表示初始加载,否则表示子级异步加载
{
如果(id=“10”)
//将3个子节点添加到id=10的父节点。
返回AddChildNodes(10,3,“xxxx”);
其他的
返回新列表();
}
List G_jstrearray=新列表();
//创建JsTree数据
//在实时场景中,这将来自db或Web服务
//添加5个根节点
G_jstrearray.AddRange(AddChildNodes(0,5,”);
//将4个子节点添加到第三个根节点
//第三个节点的id=30
//子节点将具有类似301302303304的ID
G_jstrearray[3].children=(AddChildNodes(30,4,G_jstrearray[3].data)).ToArray();
//将5个子节点添加到id=302的level1节点
G_JStrearray[3]。children[1]。children=(AddChildNodes(302,4,G_JStrearray[3]。children[1]。data)).ToArray();
返回G_jstrearray;
}
私有静态列表AddChildNodes(int\u ParentID、int numoChildren、字符串ParentName)
{
List G_jstrearray=新列表();
int n=10;
for(int i=0;i
}

我想以异步方式从asp.net页面中的webmethod加载树


提前感谢。

通过添加此完整参考,我成功地使用了此代码:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)] //ResponseFormat.Json)]
      public static List<GG_JSTree> GetAllNodes11(string id)
        {......}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat=System.Web.Script.Services.ResponseFormat.Json)]//ResponseFormat.Json]
公共静态列表GetAllNodes11(字符串id)
{......}

您现在的代码有什么具体问题?谢谢您的回复,上面的代码没有调用用url编写的webmethod。