繁体   English   中英

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

[英]how to display the php array in json format in ajax php codeigniter

我有几个错误

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

我想在ajax中显示错误,我有上面的代码,如何使用json在ajax中显示错误。 任何帮助,将不胜感激。

 var items=[]; $.each(obj, function(key, value) { items.push(value); }); 
由于它是一个关联数组,它将显示所有错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM