Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel,在重复输入上返回json错误_Php_Jquery_Laravel - Fatal编程技术网

Php Laravel,在重复输入上返回json错误

Php Laravel,在重复输入上返回json错误,php,jquery,laravel,Php,Jquery,Laravel,如何显示错误副本上的消息?表单没有完成创建过程,因为存在重复,但它只是冻结,没有显示任何消息,但是如果我将字段留空,则表明这些字段是必需的 阿贾克斯 $.ajax({ url:$('#archiveurl').attr('href'), 方法:“post”, 数据:$(“#createform”).serialize(), 发送前:函数(xhr){ 命令:toastr[“info”](“上传数据…”,“发送请求”); }, 成功:功能(结果){ toastr.clear(); if(resul

如何显示错误副本上的消息?表单没有完成创建过程,因为存在重复,但它只是冻结,没有显示任何消息,但是如果我将字段留空,则表明这些字段是必需的

阿贾克斯

$.ajax({
url:$('#archiveurl').attr('href'),
方法:“post”,
数据:$(“#createform”).serialize(),
发送前:函数(xhr){
命令:toastr[“info”](“上传数据…”,“发送请求”);
},
成功:功能(结果){
toastr.clear();
if(result.errors){
$('.alert danger').html('');
$.each(result.errors、函数(键、值){
$('.alert danger').show();
$('.alert danger')。追加('
  • '+value+'
  • '); }); }否则{ $('.alert danger').hide(); $('.alert success').show(); 命令:toastr[“success”](“添加成功”、“添加状态”、{timeOut:900}); $('.clear_此输入[type=“text”]').val(''; $('.datatable').datatable().ajax.reload(); }
    尝试此返回响应()->json(['errors'=>$validator->errors()->first()]);安装返回响应()->json(['errors'=>$validator->errors()->all()]);它将返回第一个错误,因为它将返回错误数组控制台中是否有错误?@sagarsaincar这不是working@hassanPOST 500(内部服务器错误)@在chrome中检查
    Netwrok
    选项卡,找到您的请求,检查
    预览
    读取错误,将其粘贴到此处
    public function store(Request $request)
    {
        $validator = \Validator::make($request->all(), [
            'name'=>'required|unique:countires',
            'code'=>'required|unique:countires'
        ]);
    
        if ($validator->fails()) {
            return response()->json(['errors' => $validator->errors()->all()]);
        }
    
        $this->SourceData->storeData($request->all());
        return response()->json(['success'=>'Added successfully']);
    }
    
    $.ajax({
        url: $('#archiveurl').attr('href'),
        method: 'post',
        data: $("#createform").serialize(),
    
        beforeSend: function( xhr ) {
          Command: toastr["info"]("Uploading Data ...", "Sending Request");
        },
    
        success: function(result) {
            toastr.clear();
            if(result.errors) {
                $('.alert-danger').html('');
                $.each(result.errors, function(key, value) {
                    $('.alert-danger').show();
                    $('.alert-danger').append('<strong><li>'+value+'</li></strong>');
                });
            } else {
                $('.alert-danger').hide();
                $('.alert-success').show();
                Command: toastr ["success"] ("Added successfully", "Added status",{ timeOut: 900 });
                $('.clear_this input[type="text"]').val('');        
    
                $('.datatable').DataTable().ajax.reload();                      
            }
    
    public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
             'name' => 'required|unique:countries,name',
            'code' => 'required|unique:countries,code', 
        ]);
    
        if ($validator->fails()) {
            $errors = $validator->errors();
                return response()->json(['status' => false, 'errors' => $errors]);
        }
    
        $this->SourceData->storeData($request->all());
        return response()->json(['success'=>'Added successfully']);
    }