post antiforgerytoken jquery

Solutions on MaxInterview for post antiforgerytoken jquery by the best coders in the world

showing results for - "post antiforgerytoken jquery"
Julieta
08 Oct 2018
1@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "__AjaxAntiForgeryForm" }))
2{
3    @Html.AntiForgeryToken()
4}
5
6<div id="myDiv" data-url="@Url.Action("Index", "Home")">
7    Click me to send an AJAX request to a controller action
8    decorated with the [ValidateAntiForgeryToken] attribute
9</div>
10
11<script type="text/javascript">
12    $('#myDiv').submit(function () {
13        var form = $('#__AjaxAntiForgeryForm');
14        var token = $('input[name="__RequestVerificationToken"]', form).val();
15        $.ajax({
16            url: $(this).data('url'),
17            type: 'POST',
18            data: { 
19                __RequestVerificationToken: token, 
20                someValue: 'some value' 
21            },
22            success: function (result) {
23                alert(result.someValue);
24            }
25        });
26        return false;
27    });
28</script>