laravel bootstrap模态错误

时间:2016-11-17 05:08:47

标签: ajax laravel

我在一个bootstrap模式中有一个表单,我试图显示错误并阻止它通过ajax淡出它现在它正在提交但是错误没有出现并且提交按钮被禁用,即使表单正在提交

JS

$(document).ready(function() { 
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
//login submit

$( ".registerform" ).submit(function(e ) {   
    $.ajax({
        type: "POST",
        url: '/register',
        data: $('.registerform').serialize(),
        dataType: 'json',
        cache: false,
success: function(result){
alert(result);
},
done:function( data ) {
    if(data.fail) {
      $.each(data.errors, function( index, value ) {
        var errorDiv = '#'+index+'_error';
        $(errorDiv).addClass('required');
        $(errorDiv).empty().append(value);
      });
      $('#successMessage').empty();          
    } 
    else{
        $('#register').hide(); //hiding Reg form
        var successContent = '<div class="message"><h3>Registration Completed Successfully</h3><h4>Please Login With the Following Details</h4><div class="userDetails"><p><span>Email:</span>'+data.email+'</p><p><span>Password:********</span></p></div></div>';
      $('#successMessage').html(successContent);
    } //success
  } //done



    });
  e.preventDefault(); //STOP default action
});
$( ".registerform" ).submit();   

   });

0 个答案:

没有答案