表单发送GET而不是POST [英] Form sends a GET instead of POST
本文介绍了表单发送GET而不是POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在这位自由职业者已经消失了,我正试图在没有运气的情况下进行调试。任何人都可以指出这里的html有什么问题吗?
解决方案
表单通过AJAX在main.js中使用jQuery的$阿贾克斯()。表单方法在这里没有指定,并且默认为GET。以下是修正:
//联系表单
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 (函数(数据)($ b));>< / i>电子邮件正在发送...< / p>').fadeIn());
}
})。done $ b form_status.html('< p class =text-success>感谢您与我们联系,我们会尽早与您联系< / p>')。 b $ b});
});
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?
解决方案
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();
});
});
这篇关于表单发送GET而不是POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文