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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题