我正在使用 formvalidation.io 插件,我正在尝试验证一个字段在数据库表中是唯一的。我已经完成了比较,我正在使用 ajax 返回结果(是否唯一)。我使用来自 formvalidation 插件(http://formvalidation.io/validators/callback)的“回调验证器”。这是我的代码:
callback: { //check documento no repetido
message: 'Ya existe un estudiante con el mismo número de documento',
callback: function (value, validator, $field) {
var url = "documento-existe";
$.ajax({
type: "POST",
url: url,
data: $("#numero_documento").serialize(),
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(data)
{
console.log(data);
return data;
}
});
}
}
ncaught TypeError: Cannot read property 'message' of undefined
这段代码在 javascript 控制台中给了我一个错误。为什么会造成这个错误?
我知道有一个来自 formvalidation 插件的“远程验证器”来进行 ajax-through 验证(http://formvalidation.io/validators/remote/),但我使用的是 Laravel,我必须发送 ajax 标头(X- CSRF-TOKEN),并且“远程验证器”无法发送 ajax 标头。