我的代码存在问题(如上所述):
$(function() {
var wall = new freewall("#freewall");
wall.reset({
selector: '.brick',
animate: true,
cellW: 160,
cellH: 160,
delay: 50,
onResize: function() {
wall.fitWidth();
}
});
wall.fitWidth();
var content = $.ajax({
url:"contents/home.html",
type: "GET",
dataType:"json"
});
var temp = '<div class="brick {size}">' + '<div class="covers">' + content + '</div>' + '</div>';
var size = "size33 size32 size31 size23 size22 size21 size13 size12 size11".split(" ");
$(".add-more").click(function() {
var html = "";
for (var i = 0; i < 5; ++i) {
html += temp.replace('{size}', size[size.length * Math.random() << 0])
/*.replace('{color}', colour[colour.length * Math.random() << 0])*/;
}
wall.appendBlock(html);
});
});
我尝试加载ajax内容,但它显示了[object Object]。有人可以帮忙吗?
答案 0 :(得分:0)
编写逻辑以在这样的完成函数中更新DOM,查看jQuery ajax以获取更多信息
$(function() {
var wall = new freewall("#freewall");
wall.reset({
selector: '.brick',
animate: true,
cellW: 160,
cellH: 160,
delay: 50,
onResize: function() {
wall.fitWidth();
}
});
wall.fitWidth();
var content = $.ajax({
url:"contents/home.html",
type: "GET",
dataType:"json"
}).done(function(data){
var temp = '<div class="brick {size}">' + '<div class="covers">' + content + '</div>' + '</div>';
var size = "size33 size32 size31 size23 size22 size21 size13 size12 size11".split(" ");
$(".add-more").click(function() {
var html = "";
for (var i = 0; i < 5; ++i) {
html += temp.replace('{size}', size[size.length * Math.random() << 0])
/*.replace('{color}', colour[colour.length * Math.random() << 0])*/;
}
wall.appendBlock(html);
});
});
});