tags:

views:

231

answers:

1

if so can show simple example, ex in jquery ajax.post

+2  A: 

The cookie should be sent back with the request so if you serialize the input it should work.

$('form').submit( function() {
    $.post( $(this).action, $(this).serialize(), function(data) {
         ... do something with result
    }, 'json');
    return false; // prevent default submission
});

The key is to make sure that the data that you pass back to the server contains the hidden antiforgery token input. In the case of the example above the antiforgery token must be included inside the form for it to work.

<% using (Html.BeginForm()) { %>
    <%= Html.AntiForgeryToken() %>
    ....
<% } %>
tvanfosson
if i send ajax as such... $.ajax(... can the token be included as a parameter?
zsharp
Sure: use the data option and serialize the form inputs there: data: $('#myform').serialize()
tvanfosson
ie json token=_RequestVerificationToken?
zsharp
You'd have to look up the value of the hidden input __RequestVerificationToken. So it would be __RequestVerificationToken=$('[name=__RequestVerificationToken]').attr('value')
tvanfosson
thats what i wanted and works thanks..
zsharp