2016-03-24 15 views
1

HTML:Sweetalertで確認ボタンを作成し、JavascriptとLaravel

<form id="myform" class="delete-photo col-md-12" method="POST" action="/admin/category/{{$catget->id}}"> 
     <input type="hidden" name="_method" value="delete">      
      {{ csrf_field() }}        
      <div class="form-group"> 
       <button type="submit" data-photo-id="{{$catget->id}}" 
       class="submitdel btn btn-danger" 
       >Delete Category</button> 
      </div>      
    </form> 

のJs:

<script type="text/javascript"> 
$('.delete-photo').click(function(e) { 
    e.preventDefault(); // Prevent the href from redirecting directly 
    var linkURL = $(this).attr("action"); 
    warnBeforeRedirect(linkURL); 
}); 

function warnBeforeRedirect(linkURL) { 
    swal({ 
    title: "Leave this site?", 
    text: "If you click 'OK', you will be redirected to " + linkURL, 
    type: "warning", 
    showCancelButton: true 
    }, function() { 
    // Redirect the user 
    window.location.href = linkURL; 
    }); 
} 
</script> 

私はsweetalertと確認ボタンを作成しようとしています。私は(http://localhost:8000/admin/category/13)であるルートを修正するためにリダイレクトするようにしようと試みたが、laravelは言う:RouteCollection.phpライン219で

MethodNotAllowedHttpException:....

私のルートは以下のとおりです。

Route::delete('/admin/category/{id}', '[email protected]'); 

何が間違っている可能性がありますか、その問題を修正しますか?

+0

トークンCSRFを取っていなかったのjavascript previusはあなたがlaravel 5.1 –

+0

を使用しているはい、私はルートが働いていると、ボタンがカテゴリを削除このjavasciptコードなしも追加する必要が laravel 5.1を使用しています。 –

答えて

1

JS:

$('.delete-photo').click(function(e) { 
    e.preventDefault(); // Prevent the href from redirecting directly 
    var linkURL = $(this).attr("action"); 
    warnBeforeRedirect(linkURL); 
}); 

function warnBeforeRedirect(linkURL) { 
    swal({ 
     title: "Are you sure?", 
     text: "You will not be able to recover this imaginary file!", 
     type: "warning", 
     showCancelButton: true, 
     confirmButtonColor: "#DD6B55", 
     confirmButtonText: "Yes, delete it!", 
     cancelButtonText: "No, cancel plx!", 
     closeOnConfirm: false, 
     closeOnCancel: false 
    }, 
    function(isConfirm) { 
     if (isConfirm) {       
      document.getElementById("myform").submit(); 
     } else { 
      swal("Cancelled", "Your imaginary file is safe :)", "error"); 
     } 
    } 
); 
} 

私の問題があった。 1)を削除し、アクティブコントローラメソッドにフォームを必須に提出してください。 2)

関連する問題