[英]JQuery Validator, remote rule with GET instead of POST?
I am trying to do a remote validation with JQuery Validator: 我正在尝试使用JQuery Validator进行远程验证:
rules: {
username: {
minlength: 6,
maxlength: 12,
remote: {
url: '/users/register/isUserAvailable',
dataType: 'POST',
data: {
'username': $('#username').val()
},
success: function(data) {
// success tasks...
}
}
},
I want to see if there is a way to do the validation with GET instead of POST to have it like this: 我想看看是否有一种使用GET而不是POST进行验证的方法,如下所示:
rules: {
username: {
minlength: 6,
maxlength: 12,
remote: {
url: function(){
var username = $('#username').val();
return '/users/register/isUserAvailable/' + username,
}
dataType: 'GET',
success: function(data) {
// success tasks...
}
}
},
NOTE: I know post is secure & is currently working fine, but I was just wondering if this was possible. 注意:我知道帖子是安全的,并且目前可以正常工作,但是我只是想知道是否可行。
There are a few syntax problems in your examples 您的示例中有一些语法问题
Two more points though 不过还有两点
from the docs keep it simple like so 从文档中保持它像这样简单
$( "#myform" ).validate({
rules: {
email: {
remote: {
url: "check-email.php",
type: "post",
data: {
username: function() {
return $( "#username" ).val();
}
}
}
}
}
});
我想对此没有限制,但是您需要将dataType: 'GET'
更改为type: 'GET'
Your remote syntax is incorrect, there is no success , the remote only expects a boolean value based on your supplied data 您的远程语法不正确,没有成功,远程仅根据您提供的数据期望布尔值
remote: {
type: 'GET',
url: '/users/register/isUserAvailable',
data: {
username: function() {
return $( "#username" ).val();
}
}//end remote
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.