Issue with Anti forgery token from JQuery

Topics: Writing modules
Jun 14, 2012 at 10:37 AM


I have gone through various posts here to get an ajax post working but not having much success. Please see if I am missing anything. I am getting Anti forgery error for this post.

function postImageAndCoords(params, $container, $controls, $img) {
        var token = $("input[name=__RequestVerificationToken]").val(),
            imageData = $img.attr('src'),
			fileExt = "png";
            type: 'POST',
            url: '',
            cache: false,
            timeout: 10000,
            processData: false,
            data: { __RequestVerificationToken: token, image: imageData },
            //contentType: 'image/png',
            success: function (data) {
                destroyPlugin($container, $controls, $img);


Jun 14, 2012 at 11:46 AM

This looks fine to me. Are you sure the token variable is filled correctly?

Jun 14, 2012 at 12:01 PM

Yes. I had an alert statement to check the token and that's having value so not sure what's wrong with that. Is there anyway to remove it per controller?

Jun 14, 2012 at 12:43 PM

I think there is an attribute for that, but I've never used it (and I wouldn't recommend it), there should be something still missing. Maybe somebody can see the problem, I don't...