[英]how to display the php array in json format in ajax php codeigniter
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">×</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">×</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. 我想在ajax中显示错误,我有上面的代码,如何使用json在ajax中显示错误。 any help would be appreciated.
任何帮助,将不胜感激。
var items=[]; $.each(obj, function(key, value) { items.push(value); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.