我正在尝试将远程验证器与欧芹一起使用,但我似乎无法通过请求发送附加数据。有问题的字段是电子邮件字段,我想将其发送到服务器以查看电子邮件地址是否“可用”。另外,我需要发送服务器所需的 id 参数。 id 参数嵌入在我的表单中的“主机”字段中。
因此,我尝试使用 Parsley DOM API,如下所示:
<input type="text" class="form-control" tabindex="15" id="email" name='email'
data-parsley-type="email" data-parsley-type-message="Must be a valid email format"
data-parsley-required="true" data-parsley-required-message="Email is required"
data-parsley-remote="/invitation/allowed"
data-parsley-remote-options='{ "type": "get", "data" : { "id": function() {return $("#host").val(); } }}'>
在 API 配置的最后一行中,我尝试了各种组合来将主机字段的值获取到我的 URL 中。其中包括转义函数中的引号;并证明“host”(或“#host”)作为 id 属性的值。在每种情况下,我只能获取 URL 中传递的我的电子邮件地址。
请注意,我可以毫无问题地传递文字(例如{ "id": "TestTest" }
).
我也尝试过使用 javascript,如下所示:
<script type="text/javascript" src="/js/parsley.remote.js"></script>
<script type="text/javascript">$('#employee-form').parsley({})</script>
<script type="text/javascript">
$('#email').parsley().addConstraint('remote',
{
url: '/invitation/allowed',
type: 'GET',
data: {
id: function () { return $('#host').val() }
}
})
</script>
当我这样做时,我遇到两个问题:URL 中未设置 id,而且基本 url 不正确 - 它调用当前页面的地址(不是 /invitation/allowed)。
几个小时前提出的这个问题是类似的:对依赖于其他字段的字段进行远程验证