无法转换 javascript 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3723828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:03:02  来源:igfitidea点击:

Could not convert javascript argument

javascriptjqueryajaxparsingappend

提问by Adgezaza

After trying to append some code to a div layer I received the following error and don't know why.

在尝试将一些代码附加到 div 层后,我收到以下错误,不知道为什么。

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://code.jquery.com/jquery-latest.min.js:: anonymous :: line 113" data: no]

未捕获的异常:[异常...“无法转换 JavaScript 参数 arg 0 [nsIDOMDocumentFragment.appendChild]” nsresult:“0x80570009(NS_ERROR_XPC_BAD_CONVERT_JS)”位置:“JS 框架 :: http://code.jquery.com/jquery-latest .min.js:: 匿名 :: 第 113 行”数据:无]

Below is the code that is causing the error. I understand there is some excessive code but I made it that way so it would be easy to build on for future features. Just looking for any suggestions for the error? Thank You! :)

下面是导致错误的代码。我知道有一些多余的代码,但我这样做是为了将来的功能很容易构建。只是在寻找有关错误的任何建议?谢谢!:)

 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");
    }
   }
  }); 
 }

回答by RandomBits

I don't think you can append an array. Change:

我不认为你可以附加一个数组。改变:

$('#project').append(projGallery);

To:

到:

$.each(projGallery, function(idx, val) {
    $('#project').append(val);
});