Skip to content

Commit

Permalink
fix: fix csrf token in ajax requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyker committed Dec 3, 2024
1 parent f4e6ff1 commit d35e7d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions resources/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script src="{{ asset('js/jquery.slugify.js') }}"></script>
<script src="{{ asset('js/nav-float.js') }}"></script>
<link href="{{ asset('css/OpenSansfont.css') }}" rel="stylesheet">
<meta name="csrf-token" content="{{ csrf_token() }}">
@yield('top')
</head>
<body>
Expand Down Expand Up @@ -150,6 +151,11 @@
(function ($) {
$(function () {
$.jGrowl.defaults.closerTemplate = '<div class="alert alert-info">Close All</div>';
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
});
})(jQuery);
</script>
Expand Down
10 changes: 4 additions & 6 deletions resources/views/modpack/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class="btn btn-danger btn-xs"
@endsection
@section('bottom')
<script type="text/javascript">
$("input[name=recommended]").change(function () {
$.ajax({
type: "POST",
Expand All @@ -102,7 +101,7 @@ class="btn btn-danger btn-xs"
$.jGrowl(data.success, {group: 'alert-success'});
},
error: function (xhr, textStatus, errorThrown) {
$.jGrowl(errorThrown, {group: 'alert-danger'});
$.jGrowl(errorThrown || `Unknown error: ${textStatus}`, {group: 'alert-danger'});
}
});
});
Expand All @@ -115,7 +114,7 @@ class="btn btn-danger btn-xs"
$.jGrowl(data.success, {group: 'alert-success'});
},
error: function (xhr, textStatus, errorThrown) {
$.jGrowl(errorThrown, {group: 'alert-danger'});
$.jGrowl(errorThrown || `Unknown error: ${textStatus}`, {group: 'alert-danger'});
}
});
});
Expand All @@ -131,7 +130,7 @@ class="btn btn-danger btn-xs"
$.jGrowl(data.success, {group: 'alert-success'});
},
error: function (xhr, textStatus, errorThrown) {
$.jGrowl(errorThrown, {group: 'alert-danger'});
$.jGrowl(errorThrown || `Unknown error: ${textStatus}`, {group: 'alert-danger'});
}
})
});
Expand All @@ -147,7 +146,7 @@ class="btn btn-danger btn-xs"
$.jGrowl(data.success, {group: 'alert-success'});
},
error: function (xhr, textStatus, errorThrown) {
$.jGrowl(errorThrown, {group: 'alert-danger'});
$.jGrowl(errorThrown || `Unknown error: ${textStatus}`, {group: 'alert-danger'});
}
})
});
Expand All @@ -157,6 +156,5 @@ class="btn btn-danger btn-xs"
"order": [[0, "desc"]]
});
});
</script>
@endsection

0 comments on commit d35e7d8

Please sign in to comment.