尝试将某些代码附加到div图层后,我收到了以下错误,但不知道原因。
未捕获的异常:[例外...“无法转换JavaScript参数arg 0 [nsIDOMDocumentFragment.appendChild]”nsresult:“0x80570009(NS_ERROR_XPC_BAD_CONVERT_JS)”location:“JS frame :: http://code.jquery.com/jquery-latest.min.js :: anonymous ::第113行“数据:否]
以下是导致错误的代码。我知道有一些过多的代码,但我这样做,所以很容易为未来的功能构建。只是寻找任何错误的建议?谢谢! :)
function catSelect(itm){
//params for query
var params = {
category: itm
};
var cmd = jQuery.param(params);
$.ajax({
async: false,
type: "POST",
cache: false,
url: "views/gallery.php",
data: cmd,
dataType: "json",
success: function(resp){
if(resp.status == "ok") {
$('#project').empty();
//alert(resp.projects[0]);alert(resp.files[0]); alert(resp.titles[0]);
var check = 0;
var projGallery = new Array();
for(var i in resp.projects){
if(check!=resp.projects[i] || check == 0){
projGallery[i] ='<a class="group" title="'+resp.titles[i]+'" href="images/gallery/"'+resp.files[i]+'" rel="'+resp.projects[i]+'" ><img class="group" alt="" src="../images/gallery/thumbs/"'+resp.files[i]+'"/></a>';
} else {
projGallery[i] ='<a class="group" rel="'+resp.projects[i]+'" href="images/gallery/"'+resp.files[i]+'" title="'+resp.titles[i]+'"></a>';
}
check = resp.projects[i];
}
//alert(projGallery[0]);
alert(projGallery);
$('#project').append(projGallery);
} else {
alert("Failed to select projects");
}
}
});
}
答案 0 :(得分:16)
我认为你不能追加数组。 变化:
$('#project').append(projGallery);
要:
$.each(projGallery, function(idx, val) {
$('#project').append(val);
});