laravel 5.5 ajax返回错误信息
前段ajax发送请求
$('#reg_reg').click(function () { var formData = new FormData($( "#reg_form" )[0]); var url = "{{ url('/admin/register') }}"; $.ajax({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, url: url, type: 'POST', data: formData, cache: false, contentType: false, processData: false, success: function(res){ console.log(res); // if(res.code){ // redirect_success(res.msg, res.url) // }else{ // error(res.msg); // } }, error : function (msg ) { var json=JSON.parse(msg.responseText); $.each(json.errors, function(idx, obj) { alert(obj[0]); return false; }); }, }) })
laravel 创建验证的 表单请求( form request ) 执行命令 php artisan make:request StoreBlogPostRequest