Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载JSON对象值并将它们附加到textarea中_Javascript_Jquery_Html_Json - Fatal编程技术网

Javascript 加载JSON对象值并将它们附加到textarea中

Javascript 加载JSON对象值并将它们附加到textarea中,javascript,jquery,html,json,Javascript,Jquery,Html,Json,我正在使用filestack在JSON对象中获取文档信息,但当我上传许多文件时,我希望将这些JSON值附加到textarea中 因此,我在HTML中有这样的内容: <input id="ff" type="filepicker" data-fp-apikey="myAPI" data-fp-mimetypes="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordproce

我正在使用filestack在JSON对象中获取文档信息,但当我上传许多文件时,我希望将这些JSON值附加到textarea中

因此,我在HTML中有这样的内容:

<input id="ff" type="filepicker" data-fp-apikey="myAPI" data-fp-mimetypes="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" data-fp-container="modal" data-fp-multiple="true" data-fp-button-class="btn btn-primary l-align" data-fp-button-text="Upload" data-fp-services="SKYDRIVE,COMPUTER,URL,GOOGLE_DRIVE,GMAIL" data-fp-language="en">
<textarea id="json1" name="json1" cols="30" rows="2"></textarea>
<textarea id="json" name="json" cols="30" rows="2"></textarea>
<textarea id="json" name="json" cols="30" rows="2" style="display:none;">
{"numpages":2,"dimensions":{"width":612,"height":792}} <url_of_last_file>
{"numpages":6,"dimensions":{"width":595,"height":842}} <url_of_last_file>
</textarea>

在JS中:

for(var i=0;i<event.fpfiles.length;i++){
  var link = event.fpfiles[i].url;
  var idfile = link.substr(link.lastIndexOf("/")+1);
  var lcconvert = "https://process.filestackapi.com/output=docinfo:true/"+idfile;

  $("#json1").load(lcconvert);
  document.getElementById('json').value += 
  document.getElementById('json1').value;                   
}

for(var i=0;i感谢GillesC的评论,我找到了解决方案:

$("#json1").load(lcconvert, function(result){
    $("#json").append(result);
});
编辑:现在我还需要添加每个url文件,所以我做了以下操作:

$("#json1").load(lcconvert, function(result){
    $("#json").append(result + " "+link);
});
但我只得到最后一个url文件,如HTML中的:

<input id="ff" type="filepicker" data-fp-apikey="myAPI" data-fp-mimetypes="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" data-fp-container="modal" data-fp-multiple="true" data-fp-button-class="btn btn-primary l-align" data-fp-button-text="Upload" data-fp-services="SKYDRIVE,COMPUTER,URL,GOOGLE_DRIVE,GMAIL" data-fp-language="en">
<textarea id="json1" name="json1" cols="30" rows="2"></textarea>
<textarea id="json" name="json" cols="30" rows="2"></textarea>
<textarea id="json" name="json" cols="30" rows="2" style="display:none;">
{"numpages":2,"dimensions":{"width":612,"height":792}} <url_of_last_file>
{"numpages":6,"dimensions":{"width":595,"height":842}} <url_of_last_file>
</textarea>

{“数字”:2,“尺寸”:{“宽度”:612,“高度”:792}
{“数字”:6,“尺寸”:{“宽度”:595,“高度”:842}
我想要这样:

<textarea id="json1" name="json1" cols="30" rows="2" style="display:none;">{"numpages":2,"dimensions":{"width":612,"height":792}}</textarea>
<textarea id="json" name="json" cols="30" rows="2" style="display:none;">
{"numpages":2,"dimensions":{"width":612,"height":792}} <url_of_file1>
{"numpages":6,"dimensions":{"width":595,"height":842}} <url_of_file2>
</textarea>

{“数字”:2,“尺寸”:{“宽度”:612,“高度”:792}
{“数字”:6,“尺寸”:{“宽度”:595,“高度”:842}

如何更改它?

不要使用纯JS添加内容,而是使用
append()
,并且在加载请求完成时,还需要运行更新
#json
的代码。它是异步的,因此代码不会停止并等待
加载()
使用回调完成。请参阅jquery文档。感谢您的评论,我找到了解决方案!