我遇到了花式树的问题。我有一个 aspx 页面,代码隐藏上有一个 webmethod。
我试图用 ajax 调用初始化树,但由于某种原因,它看起来 ajax 调用没有到达那里。这是我初始化树的javascript代码:
<script type="text/javascript">
$(function () {
var DT = $.ui.fancytree;
var tree = "";
$.ui.fancytree.debug("Using fancytree " + $.ui.fancytree.version);
/* Load tree from Ajax JSON
*/
$("#tree2").fancytree({
source: {
url: "tree.aspx/getTreeData"
}
});
});
</script>
这是我的代码隐藏网络方法:
namespace TreeGen
{
public partial class tree : System.Web.UI.Page
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public static List<Curso> getTreeData()
{
JavaScriptSerializer TheSerializer = new JavaScriptSerializer();
CourseSerializer course = new CourseSerializer();
course.children = new List<Curso>()
{
new Curso(){
key = "1",
title = "aaaa",
}
};
List<CourseSerializer> courses = new List<CourseSerializer>() { course };
string TheJson = TheSerializer.Serialize(course.children);
Console.WriteLine(TheJson);
return course.children;
}
}
}
我究竟做错了什么?我尝试向 webmethod 发出 ajax 请求,并且能够检索 json 字符串。但是当我使用花式树时,我无法填充树!
提前致谢!问候!