layui 表单输入框能用ajax验证吗

2025-05-05 05:06:54
推荐回答(1个)
回答1:

试试这个方法,看行不行。
form.verify({
username: function(value) {
$.ajax({
async: false, // 使用同步的方法
data: { //要提交到服务端验证的用户名
userName: value
},
dataType: 'json',
success: function(result) { //栗子,返回的数据结果:{"rel":true,"message":"用户名已存在!"}
if (result.rel) {
return result.message;
}
},
url: 'http://xxx.com/api/' // 这里写你要验证的地址哦。
});
}
});