【问题标题】:jsTree 3.0.2 - How to pass parameter to aspx webmethodjsTree 3.0.2 - 如何将参数传递给 aspx webmethod
【发布时间】:2014-07-24 12:52:02
【问题描述】:

我正在尝试将 jsTree 3.0.2 中的参数传递给 aspx 页面上的 web 方法,但它没有命中 web 方法。但是,当没有参数时它确实有效。谁能指出我的方法的错误?

带参数(不工作):

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll(string id)
{
    // method does not get called
}

$("#jsTreeTest").jstree({
    "core": {
        "data": {
            "url": "MyPage.aspx/GetAll",
            "type": 'POST',
            "dataType": 'JSON',
            "contentType": 'application/json;',
            'data': function (node) {
                return { 'id': "01" };
            }
        }
    }
});

无参数(工作):

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll()
{
    // successfully calls method
}

$("#jsTreeTest").jstree({
    "core": {
        "data": {
            "url": "MyPage.aspx/GetAll",
            "type": 'POST',
            "dataType": 'JSON',
            "contentType": 'application/json;',
            "data": function (node) { return {}; }
        }
    }
});

谢谢。

【问题讨论】:

    标签: c# asp.net web-services jstree


    【解决方案1】:

    发现问题。应该是:

    return '{ "id" : "01" }';
    

    工作代码:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static IEnumerable<JsTreeNode> GetAll(string id)
    {
        // success!
    }
    
    $("#jsTreeTest").jstree({
        "core": {
            "data": {
                "url": "MyPage.aspx/GetAll",
                "type": 'POST',
                "dataType": 'JSON',
                "contentType": 'application/json;',
                "data": function (node) {
                    return '{ "id" : "01" }';
                }
            }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 2010-10-18
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      相关资源
      最近更新 更多