Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

post antiforgerytoken jquery

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "__AjaxAntiForgeryForm" }))
{
    @Html.AntiForgeryToken()
}

<div id="myDiv" data-url="@Url.Action("Index", "Home")">
    Click me to send an AJAX request to a controller action
    decorated with the [ValidateAntiForgeryToken] attribute
</div>

<script type="text/javascript">
    $('#myDiv').submit(function () {
        var form = $('#__AjaxAntiForgeryForm');
        var token = $('input[name="__RequestVerificationToken"]', form).val();
        $.ajax({
            url: $(this).data('url'),
            type: 'POST',
            data: { 
                __RequestVerificationToken: token, 
                someValue: 'some value' 
            },
            success: function (result) {
                alert(result.someValue);
            }
        });
        return false;
    });
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: regex match everything before string 
Javascript :: chartjs start at 0 
Javascript :: 0.1 + 0.2 javascript 
Javascript :: express request path 
Javascript :: react after deployment givin nginx 404 
Javascript :: create react native app 
Javascript :: javascript sort array of objects by date 
Javascript :: find base url in javascript 
Javascript :: random code js 
Javascript :: javascript queryselector data attribute 
Javascript :: trheejs cube mesh 
Javascript :: validate aadhaar number in javascript 
Javascript :: read only javascript 
Javascript :: javascript detect click outside of element 
Javascript :: install node js windows powershell 
Javascript :: react router dom 
Javascript :: Im not getting req.body 
Javascript :: regex to extract valid http or https 
Javascript :: javascript button go to url 
Javascript :: angular reactive form remove validation 
Javascript :: check if radio button is checked 
Javascript :: Only numbers or string. Input field in React 
Javascript :: how to find the key of an value in an object 
Javascript :: localstorage is not defined 
Javascript :: js number add zero before 
Javascript :: window.open javascript auto close 
Javascript :: MIN_SAFE_INTEGER 
Javascript :: js self executing anonymous function 
Javascript :: js mobile prevent image mousedown 
Javascript :: replace globally in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =