0

次のようなコードで作成された jsTree を実装しました。

}).jstree({
        "json_data": {
            "ajax": {
                "url": '<% =  ResolveClientUrl("../GetTree.asmx/FullTree") %>',
                "async": true,
                "contentType": "application/json; charset=utf-8",
                "dataType": "json",
                "success": function (data, textStatus, jqXHR) {
                    alert("Transmission Success.");
                    alert(data);
                    var obj = $.parseJSON(data);
                    alert("Parsing JSON Success.");
                    // Can I access the return value of the web service FullTree function here?
                    return data.d;
                },
                "data": function (n) {
                    return {
                        id: nodoIniziale,
                        level: 0
                    };
                },
            },
            "progressive_render": true
        },

ASP.NET 関数は次のようなものです。

[WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
public int MacchineFullTree()
{
        List<jsTreeNewNode> nodes = new List<jsTreeNewNode>();
        int retValue;
        // ============== 
        // Code that creates the Tree and assign retValue = xxx
        // ============== 
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        string nodesSerialized = serializer.Serialize(nodes);

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/json; charset=utf-8";
        HttpContext.Current.Response.AddHeader("Content-Length",        nodesSerialized.Length.ToString(CultureInfo.InvariantCulture));
        HttpContext.Current.Response.AddHeader("Connection", "Close");
        HttpContext.Current.Response.Write(nodesSerialized);
        HttpContext.Current.Response.Flush();

        return retValue;

Web サービスの戻り値にアクセスするにはどうすればよいですか? (これが理にかなっている場合)(int値ではなく、Webサービス関数からオブジェクトを返す方が良いでしょう... ;-))

重要な編集

私の Web サービス関数が単に次のようになる場合public int MacchineFullTree() { return 9999; }成功関数でdata.d を問い合わせる戻り値を取得できます。

ただし、私の場合、サーバーの応答を「強制」しHttpContext.Current.Response.Write(nodesSerialized);、問い合わせdata.dていますundefined

4

1 に答える 1

0

この実現可能で単純な解決策を見つけました;-) 関数の戻り値を使用する代わりに、ツリーノードをもう少し「拡張」し、ルートノードに値をノード istelf の属性として追加します。

rootNode.retValue = xxx

(もちろん、これを行うために、jsTreeNode クラスを変更しました)。

欠点:ツリーのすべてのノードがこの属性を持つようになったため、サーバーの応答の長さが長くなります。

于 2013-09-19T06:23:53.307 に答える