织梦dedecms留言表单系统ajax请求示例

html 部分

<form enctype=”multipart/form-data” method=”post” onsubmit=”return check(this)”>

<div class=”d01″>
<input type=’text’ name=’company’ id=’company’ class=’e01′ placeholder=”公司名称” value=” />
<input type=’text’ name=’name’ id=’name’ placeholder=”姓名” class=’e01 e02′ value=” />
</div>
<div class=”d01″>
<input type=’text’ name=’zhiwei’ id=’zhiwei’ placeholder=”职位” class=’e01′ value=” />
<input type=’text’ name=’tel’ id=’tel’ class=’e01 e02′ placeholder=”联系方式” value=” />
</div>
<div class=”d02″>
<input type=’text’ name=’yewu’ id=’yewu’ class=’e01′ placeholder=”主营业务” value=” />
</div>
<div class=”d03″>
<textarea name=’xuqiu’ id=’xuqiu’ class=”e01″ placeholder=”合作需求”></textarea>
</div>
<div class=”d04″>
<input type=”submit” name=”submit” value=”提 交” class=’e01′ />
</div>
</form>

js 部分

function check(form) {
const company = form.company.value;
const name = form.name.value;
const zhiwei = form.zhiwei.value;
const tel = form.tel.value;
const yewu = form.yewu.value;
const xuqiu = form.xuqiu.value;

if (!tel) {
alert(‘请输入联系方式!’);
form.tel.focus();
return false;
}

function phoneFun(phones) {
let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
if (!myreg.test(phones)) {
return false;
} else {
return true;
}
}

if (!phoneFun(tel)) {
console.log(tel);
alert(“请正确的手机号码!”);
form.tel.focus();
return false;
}

const dataString =
‘company=’ + company +
‘&name=’ + name +
‘&zhiwei=’ + zhiwei +
‘&tel=’ + tel +
‘&yewu=’ + yewu +
‘&xuqiu=’ + xuqiu +
‘&action=post’ +
‘&diyid=1&do=2&dede_fields=company,text;name,text;zhiwei,text;tel,text;yewu,text;xuqiu,multitext&dede_fieldshash=0e68297e08576bda73155ce736f0cc45’;

$.ajax({
type: “POST”,
url: “/plus/diy.php”,
data: dataString, //传值
success: function(data) {
alert(“手机提交成功,稍后客服人员将与您联系!”);
window.location.href = window.location.href;
}
});

return false;
}

亲测完美,解决了我的留言板问题!

赞 (2)

评论

3+1=