无法发送 "POST "表单,jQuery无法检测到提交动作。

问题描述 投票:0回答:1

我点击按钮后无法发送表单,我怀疑是jQuery无法检测到提交动作。是jQuery检测到提交动作后才发送表单的。我用debugger追踪点击动作到jquery.js(3.5.1),如下图所示。提交动作函数本身是一个自定义的文件代码(下面我也会注明)。

我用Mozilla检查后发现,POST(xhr):status、transfer和header都没有值。

如果你知道如何解决这个问题,请一步一步地解释它。我将非常感激

jQuery.js事件监听器断点图片。断点1

断点2

自定义JS代码。

$(".submitForm").on("click", function() {
		var _this = $(this);
		var targetForm = _this.closest('form');
		var errroTarget = targetForm.find('.response');
		var check = checkRequire(targetForm , errroTarget);
		if(check == 0){
			var formDetail = new FormData(targetForm[0]);
			formDetail.append('form_type' , _this.attr('form-type'));
			$.ajax({
				method : 'post',
				url : 'ajax.php',
				data:formDetail,
				cache:false,
				contentType: false,
				processData: false
			}).done(function(resp){
				if(resp == 1){
					targetForm.find('input').val('');
					targetForm.find('textarea').val('');
					errroTarget.html('<p style="color:green;">Mail has been sent successfully.</p>');
				}else{
					errroTarget.html('<p style="color:red;">Something went wrong please try again latter.</p>');
				}
			});
		}
	});

HTML代码在这里。

<form>
  <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    <input type="text" name="full_name" placeholder="Full Name" class="require">
    <input type="text" name="email" placeholder="Email" class="require" data-valid="email" data-error="Email should be valid.">
    <input type="text" name="contact_no" placeholder="Phone" class="require">
  </div>
  <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    <textarea rows="7" name="message" placeholder="Message" class="require"></textarea>
  </div>
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="response"></div>
  </div>
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="wd_btn">
      <button type="button" class="submitForm" form-type="contact">Send a Message</button>
    </div>
  </div>
</form>
javascript jquery forms post breakpoints
1个回答
0
投票

我找到了问题的解决方法。原来这个问题是在最新的windows 10更新后出现的。它影响了我的WAMP软件,在我卸载了WAMP服务器并安装了最新的XAMP服务器版本后,问题就停止了。现在代码工作得很好。

当我找不到错误时,它开始让我疯狂。非常感谢大家的回复。

© www.soinside.com 2019 - 2024. All rights reserved.