$(document).ready( ()=> { $("form").submit(function (e) { let data = {}; let formvalue = $("#consultForm").serializeArray() $.each(formvalue, function (index, item) { data[item.name] = item.value }); let errorMessage = "" if (data['project'] === '') errorMessage = "请填写咨询项目" if (data['detail'] === '') errorMessage = "请填写咨询详情" if (data['name'] === '') errorMessage = "请填写您的姓名" if (data['organize'] === '') errorMessage = "请填写公司/机构/学校名称" if (data['province'] === '') errorMessage = "请填写省市/自治区" if (data['city'] === '') errorMessage = "请填写直辖市" if (data['address'] === '') errorMessage = "请填写地址" if (data['phone'] === '') errorMessage = "请填写电话号码" if (data['email'] === '') errorMessage = "请填写邮件地址" if (data['reading'] !== 'yes') errorMessage = "请同意富士模具的隐私条款" if (errorMessage.length > 0) { alert(errorMessage) return false } let regPhone = /\d/; if (!regPhone.test(data['phone'])) { alert("请填写正确的电话号码") $("input[name='phone']").focus() return false } let regEmail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/ if (!regEmail.test(data['email'])) { alert('请填写正确的邮件地址') $("input[name='email']").focus() return false } let request_url = "/contact/submit?lang=jp" $.ajax({ type: 'POST', url: request_url, dataType: 'json', data: formvalue, beforeSend: function (xhr) { $('#submitForm').attr('disabled', "true").text('发送中...') xhr.setRequestHeader('token', $("#token").val()); }, success : function (res) { if (parseInt(res.code) === 10000) { alert(res.message); $('#submitForm').text('提交').removeAttr("disabled") if ('url' in res.data) { window.location.href = res.data.url } else { window.location.record() } } else { alert(res.message); $("#token").val(res.data['token']) $('#submitForm').text('提交').removeAttr("disabled") } tkHide() }, error : function (res) { let httpStatus = parseInt(res.status) let msg = ('message' in res.responseJSON) ? res.responseJSON.message : '发送失败,请更新重试。' if (httpStatus === 500) { msg = "发送失败,请更新重试。" } $('#submitForm').text('送信').removeAttr("disabled") $("#token").val(res.responseJSON.data['token']) tkHide() return false } }) e.preventDefault(); return false }) } )