Welcome Guest, Not a member yet? Register   Sign In
POST via Ajax returns 403 with CSRF enabled
#5

(04-06-2020, 12:08 PM)Gary Wrote: Once you've checked the setting CSRFRegenerate is FALSE, it may be worth trying setting dataType: 'html' in your AJAX routine (?).

You could also try removing contentType: "application/json" to see whether that makes a difference.

Hi Gary,

The contentType was causing this malfunction... IMO it doesn't make any sense but at least now it's working, here the working Ajax function:
Code:
const sendContactForm = (contactFormData) => {
    $.ajax({
        type: 'POST',
        url: apiUrl,
        data: contactFormData,
        //contentType: "application/json", THIS WAS CAUSING THE MALFUNCTION
        headers: {'X-Requested-With': 'XMLHttpRequest'},
        dataType: 'json',
        success: function(result){
            console.log(result);
        },
        error: function(result){
            console.log(result.responseJSON);
        }
    })
}

Now that it works, could you please clarify if this is expected? Why the contentType was causing this? It should be included, don't you think?

Thanks
Reply


Messages In This Thread
RE: POST via Ajax returns 403 with CSRF enabled - by marcvidalim - 04-06-2020, 12:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB