开发者

Jquery remote validation timeout

I am trying to use jquery validation to validate some input values on the form. On one of the form I have to make a remote call to the server to check if the required entered value is valid or not. So I have something like:

$("#myform").validate({
rules: {
zip: {
  required: true,
  开发者_JAVA百科zip: true,
  remote: "check-zip.action"
  }
 }
});

Now for some very unusual testing scenario - I need to handle the validation, when a server does not respond to the remote call. I see through a javascript plugin (google pagespeed)... that the remote call to the server for validation keeps on hanging out... even if the server is down. I am having hard time figuring out if there is a timeout or something I could use so that after trying to connect for desirable number of seconds.. I could call out a javascript function to display the user that ... the server was unavailable to validate the zip code.. or some other meaningful message. i tried adding timeout:10000, but did not work.. Any help is greatly appreciated.

Thanks


Thanks a lot for your answer... but I was more looking for a particular remote call during validation.

Anyways... looks like I could use

$("#myform").validate({
rules: {
zip: {
  required: true,
  zip: true,
  remote: 
  {
   url:"check-zip.action",
   timeout:2000,
   error:handleerror
  }
 }
 }
});

and this will call the js function handleerror(request,error) if the ajax call times out, or that the server is not available, depending on what comes back in the request parameter.

Thanks,


I'm not sure but you can try jQuery Ajax with callbacks.

Here is the sample:

$.ajax({
 url: 'ajax/test.html',
 success: function(data) {
   $('.result').html(data);
   alert('Load was performed.');
 },
 error: function(obj, errorText, exception){
   alert('Error: ' + errorText);
 }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜