Php fancytree未加载json数据
我试图使用fancytree显示从php rest服务返回的一些数据。该服务返回的数据已通过JSONLint验证,并以fancytree文档中显示的格式显示 如果打开开发者工具窗口(Chrome),它会在jquery-1.11.3.min.js:2文件中显示错误“未捕获错误:未实现” 当我验证返回的JSON数据时,我使用的是高级Rest客户端(Google App),我删除了高级Rest客户端显示的字符串周围的双引号,然后将值粘贴到JSONLint中 我的jquery代码:Php fancytree未加载json数据,php,jquery,json,loading,fancytree,Php,Jquery,Json,Loading,Fancytree,我试图使用fancytree显示从php rest服务返回的一些数据。该服务返回的数据已通过JSONLint验证,并以fancytree文档中显示的格式显示 如果打开开发者工具窗口(Chrome),它会在jquery-1.11.3.min.js:2文件中显示错误“未捕获错误:未实现” 当我验证返回的JSON数据时,我使用的是高级Rest客户端(Google App),我删除了高级Rest客户端显示的字符串周围的双引号,然后将值粘贴到JSONLint中 我的jquery代码: <script
<script type="text/javascript">
$(function(){
var phpAPI = "http://localhost/clubjudge/api/JSONClassTree2";
$.getJSON(phpAPI)
.done(function(json) {
alert(json);
$("#tree").fancytree({
source: json
}
);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", "+ error;
console.log("Request Failed: "+ err );
});
});
</script>
对不起,我意识到有很多。这也是Advanced Rest客户端显示的(在去掉外部双引号之后)。不确定这是否解决了您的问题,但您不需要发出单独的ajax请求。Fancytree直接支持这一点:
$("#tree").fancytree({
source: {
url: "/clubjudge/api/JSONClassTree2",
cache: false
},
...
});
有关详细信息,请参见此处:您可以将请求中的JSON数据加载到源:
$("#tree").fancytree({
source: $.ajax({
url: "/clubjudge/api/JSONClassTree2",
dataType: "json"
})
});
可能您的json变量是json字符串,FancyTree希望它是JS对象,所以您应该首先使用json.parse()。这对我很有帮助
$("#tree").fancytree({
source: $.ajax({
url: "/clubjudge/api/JSONClassTree2",
dataType: "json"
})
});