次のようなコードで作成された 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
。