【问题标题】:Fancytree not loading with ajax requestFancytree 未加载 ajax 请求
【发布时间】:2014-06-25 21:25:20
【问题描述】:

我遇到了花式树的问题。 我有一个 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 字符串。 但是当我使用花式树时,我无法填充树!

提前致谢! 问候!

【问题讨论】:

    标签: c# javascript jquery ajax fancytree


    【解决方案1】:

    对于任何有兴趣的人... fancytree 发出的 ajax 请求默认都是“GET”请求。 我添加了如下所示的ajax选项,现在问题已经解决了。

    $('#tree2').fancytree({
        ajax: { type: "POST", contentType: "application/json" },
        source: {
            url: "/tree.aspx/getTreeData"
        }
    });
    

    问候!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多