Form sends a GET instead of POST

我是研究僧i 提交于 2019-12-25 06:59:37

问题


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?


回答1:


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();
    });
});


来源:https://stackoverflow.com/questions/36608614/form-sends-a-get-instead-of-post

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!