Ajax form submit

I have a form inside popup. i need validation only at submit , how to process the validation errors from ajax submit .

This is my action


        $model = new UserVisit();


        if ($model->load(Yii::$app->request->post())) {

            if(isset($_POST['date_selected'])){

                $model->arrival_date = strtotime($_POST['date_selected']);

                $model->departure_time = $model->arrival_date+60*30;

            }

            if($model->save()){

                Yii::$app->response->format = 'json';


                $msg = 'Schedule created successfully.';


                return [

                    'status'=>'success',

                    'message' => $msg,

                ];

            }else {

                Yii::$app->response->format = 'json';

                return \yii\widgets\ActiveForm::validate($model);

            }

        } 

csrf error?

ajax code:




var m = $('meta[name=csrf-token]');

$.ajax({

    type:'type',

    url:'url',

    dataType:'JSON',

    data:{_csrf:m.attr('content')},

    success:function(data){}

})



This is my submit js




$this->registerJs("$('form#request-password-reset-form').on('beforeSubmit', function(e) {

  var form = $(this);                         		

        if(form.find('.has-error').length) {

            return false;

        }                   			

        $.ajax({

            url: form.attr('action'),

            type: 'post',

            data: form.serialize(),

            success: function(response) {    

                console.log(response);

            }

   	});                              

   	return false;

    }).on('submit', function(e){

        e.preventDefault();

    });");