我对 fancytree 有疑问。 我有一个 aspx 页面,在代码隐藏中有一个 web 方法。
我试图用 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>
这是我的代码隐藏 web 方法:
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 字符串。 但是当我使用 fancytree 时,我无法填充树!
提前致谢! 问候!
最佳答案
对于任何感兴趣的人... fancytree发出的ajax请求默认都是“GET”请求。 我添加了如下所示的 ajax 选项,现在问题已解决。
$('#tree2').fancytree({
ajax: { type: "POST", contentType: "application/json" },
source: {
url: "/tree.aspx/getTreeData"
}
});
问候!
关于c# - Fancytree 没有加载 ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24394424/