Aditya Patawari
Aditya Patawari

Reputation: 819

Form sends a GET instead of POST

I got a website built for my small business from a freelancer. The website is hosted at http://devopsnexus.com/. Everything looks fine except the form in the bottom which is sending GET instead of POST. Strangely, if I just copy the code within the form tag in a new html file, it works just fine. Now the freelancer has vanished and I am trying to debug since hours without an luck. Can anyone point out what is wrong with html here?

Upvotes: 0

Views: 1142

Answers (1)

Steve
Steve

Reputation: 569

The form is being submitted via AJAX in main.js using jQuery's $.ajax(). The form method isn't specified here, and is defaulting to GET. Here's the fix:

// Contact form
var form = $('#main-contact-form');
form.submit(function(event) {
    event.preventDefault();
    var form_status = $('<div class="form_status"></div>');
    var formData = $(this).serialize();
    $.ajax({
        url: $(this).attr('action'),
        method: 'POST',
        data: formData,
        beforeSend: function() {
            form.prepend(form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn());
        }
    }).done(function(data) {
        form_status.html('<p class="text-success">Thank you for contact us. As early as possible  we will contact you</p>').delay(3000).fadeOut();
    });
});

Upvotes: 2

Related Questions