我对fancytree有点问题。我有一个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> 这是我的代码幕后webmethod:
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时,我不能填充树!
提前感谢!致以问候!
发布于 2014-06-25 21:25:21
对于感兴趣的人..。默认情况下,fancytree发出的ajax请求都是"GET“请求。我添加了如下所示的ajax选项,现在问题就解决了。
$('#tree2').fancytree({
ajax: { type: "POST", contentType: "application/json" },
source: {
url: "/tree.aspx/getTreeData"
}
});致以问候!
https://stackoverflow.com/questions/24394424
复制相似问题