在远程验证中将数据传递到服务器 [英] Passing data to server in remote validation
问题描述
在其中一个字段上使用带有remote的jquery验证.如何将用户输入的数据发送到服务器?
Using jquery validation with remote on one of the fields. How do I send the data to the server of what the user entered into the field?
rules: {
"profile.userId": {
required: true,
minlength: 8,
remote: {
url: "/checkUniqueUserId",
dataType: "json",
type: "POST",
data: {userId : '???'}
}
}
如何在输入字段中提取输入的值?我尝试过:
How do I extract the entered value in the input field? I've tried:
-
$("#userId").val()
-
userId
-
profile.userId
-
$(this).val()
$("#userId").val()
userId
profile.userId
$(this).val()
有什么建议吗?
这是在我的jsp中:
<div class="control-group">
<div class="form-group has-success has-feedback">
<form:input type="text" id="userId" name="userId" class="form-control"
path="profile.userId" placeholder="user name"/>
</div>
</div>
推荐答案
引用OP :
如何将用户输入的数据发送到服务器?"
您不这样做,因为默认情况下已经发送了该邮件.
You don't, because that is already sent by default.
您的代码...
rules: {
"profile.userId": { // <- this MUST be the 'name' attribute of the input
required: true,
minlength: 8,
remote: {
url: "/checkUniqueUserId",
// dataType: "json", // <- not needed, default
type: "POST",
// data: {userId : '???'} // <- not needed
}
}
}
如果只需要profile.userId
字段的值,则无需执行任何操作.这就是默认情况下已经发送的确切数据.
If you just want the value of your profile.userId
field, you don't need to do anything. That's the exact data already sent by default.
以PHP为例,可以通过$_POST
数组作为$_POST['profile.userId']
在服务器端进行简单访问. (这假定渲染的<input>
元素包含name="profile.userId"
属性,否则这些都不起作用.)
Using PHP as an example, it is simply accessed server-side with the $_POST
array as $_POST['profile.userId']
. (This assumes the rendered <input>
element contains the name="profile.userId"
attribute, otherwise none of this will work.)
仅当需要将其他数据发送到远程脚本时,才使用data
选项 .例如,发送电子邮件地址和用户ID.
You would only use the data
option if you need to send additional data to the remote script. Example, to send an email address along with the user id.
这篇关于在远程验证中将数据传递到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!