Error 415 (Unsupported Media Type) While submitting Hubspot Form using Ajax

companies
forms
contacts

#1

I am facing an issue while submission of HS for using Ajax . i am submitting the HS form using ajax, getting the values through HTML form and passing the same values to HS forms and submitting the form by button click using ajax, but now am facing an error
"error 415 (Unsupported Media Type)"
Can any one please help me

Thanks


#2

Hi @Subin_Das,

Can you post the full request you’re making to HubSpot? Are you setting the Content Type header to application/x-www-form-urlencoded?


#3

Thanks for your reply @Derek_Gervais,
I have solved the issue by passing the values like this please check the code :

    var frm = $('#hsForm_ID');
    var data = new FormData($('#hsForm_ID')[0]);
            // e.preventDefault();
            $.ajax({
                type: frm.attr('method'),
                url: frm.attr('action'),
                cache: false,
                contentType: false,
                processData: false,
                data: data,
                success: function (data) {
                    console.log('Submission was successful.');
                    
                    console.log(data);
                },
                error: function (data) {
                    console.log('An error occurred.');
                    console.log(data);
                },
            }); 

Thanks