jQuery验证-等待远程检查完成 [英] jquery validation - waiting for remote check to complete
问题描述
当我呼叫$("form").valid()
时,我挂接了一个远程验证检查(这一切都很好),但是,如果所有其他字段都有效,则表单通过验证,因为远程检查没有返回足够快"的响应.
When I call $("form").valid()
I have a remote validation check hooked up (which all works well) however if all other fields are valid the form passes validation because the remote check hasn't return a response "quick enough".
是否有一种方法可以强制jquery验证等待任何远程检查完成,或者挂接到远程检查调用的complete事件?
Is there a way to either force jquery validation to wait for any remote checks to be completed or hook into the complete event of the remote check call?
我目前正在使用内置在jQuery验证框架中的远程验证器 http://docs .jquery.com/Plugins/Validation/Methods/remote
I am currently using the remote validator built into the jQuery validation framework http://docs.jquery.com/Plugins/Validation/Methods/remote
推荐答案
一种方法是引入一个变量,该变量在远程调用返回时将设置为true
one way is to introduce a variable that will be set to true when the remote call comes back
var remote_complete = false;
$.ajax({
url: "test.html",
success: function(){
remote_complete = true;
}
});
while (remote_complete == false)
{
// loop until remote_complete = true;
}
另一种方法是在远程验证完成后验证表单
Another way is to validate your form after remote validation completes
$.ajax({
url: "test.html",
success: function(){
validate_form();
}
});
这篇关于jQuery验证-等待远程检查完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!