dscc90150010 2016-05-26 08:00
浏览 46
已采纳

如何在ajax php codeigniter中以json格式显示php数组

I have couple of errors

$errors = array();
$errors['failed'] = "File uplaoded failed Please correct the following error";
$errors['size'] = 'File size must be 100 MB';
$errors['ext'] = "This formate does not support, Only .zip supported";
$errors['exits'] = "Sorry, file name already exists ,Please enter another theme name";
echo json_encode($errors)

$(function() {
     $('#addTheme').submit(function(e) {         
               e.preventDefault(); //ok
               var data = new FormData($(this)[0]);
              $.ajax({
                 url: '<?php echo base_url() ?>download/uploaded',
                 type: 'POST',
                 data: data,
                 dataType : 'json',
                 contentType: false,
                 cache: false,
                 processData: false,

                 success : function(response) {
                     $('.populate').val('');
                   var obj = jQuery.parseJSON(JSON.stringify(response));
                   if(obj.value === 1) {
                     $('#error').html('<div class="alert alert-success alert-dismissible" role="alert">'+
                        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+'File uploaded successfully</div>');
                 } else {
                    $('#error').html('<div class="alert alert-success alert-dismissible" role="alert">'+
                        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+'File uploaded failed'+   +'</div>');
                 }
                 console.log("upload success");
            },
        });
             
             

         });     
 });
    

i want to display the errors in ajax, i have the above code, how could i display the error in ajax using json. any help would be appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • dtqi87613 2016-05-26 08:45
    关注

    var items=[];
    $.each(obj, function(key, value) {
    items.push(value);
    });

    since it is an associative array, it will display all the error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于 S7-PLCSIM Advanced 5.0本地TCP连接无法读写数据
  • ¥15 关于温度改变石墨烯介电性能(关键词-介电常数)
  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下