现在我可以加载json网页中3个不同部分的内容,但会显示通过函数中的变量传递内容的几个错误。我解释。jquery + json加载内容但在萤火虫控制台中显示错误
第一节使用jquery函数从file1.json加载内容。
脚本首节
var f = $(this).data('residentidx');
$.getJSON("file1.json", function(data) {
$("#tt_mn").html($("<p class='prod_c'>" + data.articles[f].title + "</p>"));
$("#content_mn").html($("<p class='prod_d'>" + data.articles[f].esquema + "</p>"));
});
file1.json
{"articles":
[{"title":"......", "esquema":"............"}, ...,{"title":".....","esquema":"......"}]}
脚本POR第二段
var i = $(this).data('renovidx');
$.getJSON("file2.json", function(data) {
$("#tt_mn").html($("<p class='prod_c'>" + data.articles[i].title + "</p>"));
$("#content_mn").html($("<p class='prod_d'>" + data.articles[i].esquema + "</p>"));
});
file2.json
{"articles":
[{"title":"......", "esquema":"............"}, ...,{"title":".....","esquema":"......"}]}
所有似乎都没问题的事实数据显示正确,但它显示萤火虫控制台中的错误。
data.articles[i] is undefined @ http://www.xxxxx.com/js/jquery-1.7.1.min.js:14
真奇怪,因为当我在第2节中的jQuery功能使用[F]值找到JSON数组元素[I]值萤火控制台显示错误。
谢谢
是的,我做到了。它的好 –