This project is read-only.

Issue with Anti forgery token from JQuery

Topics: Writing modules
Jun 14, 2012 at 11: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 12:46 PM

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

Jun 14, 2012 at 1: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 1: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...