首页 > 解决方案 > 打印具有 php 数组值的 json 值

问题描述

{"success":"","error":"<span style='color: red;' id='inin'><p>The image you are attempting to upload doesn't fit into the allowed dimensions.<\/p><p>The image you are attempting to upload doesn't fit into the allowed dimensions.<\/p><\/span>",**"file":["asdf.PNG,","asdfgvb.PNG,"]**}

如何在 JavaScript 警报中打印 JSON 文件值

标签: javascriptphparrayscodeigniter

解决方案


您必须捕获来自 xhr、JSON.Parse 的响应,然后才能将其用作对象。就像警报中的 object.error 或其他东西一样。

所以在最简单的解决方案中:

var obj = JSON.parse('{"success":"","error":"<span style='color: red;' id='inin'><p>The image you are attempting to upload doesn't fit into the allowed dimensions.<\/p><p>The image you are attempting to upload doesn't fit into the allowed dimensions.<\/p><\/span>","file":["asdf.PNG,","asdfgvb.PNG,"]}');

var d1 = document.getElementById('div');
d1.insertAdjacentHTML('beforeend', obj.error);

推荐阅读