Ajax getting 400 Bad Request when submitting Form only on Firefox

  ajax, jquery, php, wordpress

I have written a php code in wordpress to submit a form using ajax. It working fine on chrome but getting 400 Bad request on Firefox. This is my code:

jQuery(document).ready(function($){
    jQuery( 'form[name="contact-me"]' ).on( 'submit', function(e) {
        e.preventDefault();
        var form_data = {};
         $(this).serializeArray().forEach( function(element){
            form_data[element.name] = element.value;
        });
        $.post(zt_send_form_obj.ajax_url, {
            action:      "zt_save_campain_form_data",
            _ajax_nonce:   zt_send_form_obj.nonce,
            type: "POST",
            contentType: 'application/json; charset=utf-8',
            values: JSON.stringify(form_data),
        }, function(data) {
            if (data.success) {
                if(data.data.info.message=='no'){
                    $('#myModal').show();
                    console.log('cod is in')
                }
                if(data.data.info.message=='yes'){
                    $('#CodeModal').show();
                    $('.the_cod_div').append('<span>'+data.data.info.code+'</span>');
                    console.log('data saved');
                }
                
            }
            else{
                console.log("not working");
            }
        });
    });
});

Source: Ask PHP

LEAVE A COMMENT