【发布时间】:2013-09-17 13:02:07
【问题描述】:
我已经实现了一个用这样的代码创建的 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 服务返回值? (如果这是有道理的) (更好的是从 Web 服务函数返回一个对象,而不是一个 int 值...... ;-))
重要编辑
如果我的网络服务功能只是:public int MacchineFullTree() { return 9999; }
然后在 success 函数中,我可以获得询问 data.d 的返回值。
但是在我的情况下,我用HttpContext.Current.Response.Write(nodesSerialized);“强制”服务器响应并询问data.d我得到undefined。
【问题讨论】:
标签: javascript jquery asp.net ajax jstree