jquery - AJAX Post on Field Completion? -


i have code below validates form field called lms_domain. checks whether subdomain selected user available using ajax call file executes mysqli count query. code works on submission of form execute ajax post when user types field, or has completed field. how achieve using jquery?

$('#lms_name').keyup(function(){      /* code here */      $.ajax({         type: 'post',         url: 'assets/lmsdomaincheck.php',         data: "lmsdomain="+value+".thedomain.com",         async: false,         success: function(htmldata){              if (htmldata=="success") {                 $('#spanlmsdomain').html('good');             }else {                 msg+="<b>error on lms domain name : </b>"+value+".thedomain.com not available.<br/>";                 $('#spanlmsdomain').html('bad');             }         }     });      /* code here */  }); 

thanks in advance tips!

$('#lms_name').on('blur', function() { 

this execute once cursor leaves field, indicating completion of user input.

var busy = false; $('#lms_name').on('blur keyup keypress', function(e) {     if ((e.type == 'keyup' || e.type == 'keypress') && busy === false) {         busy = true;         var avail = settimeout(function() {             $.ajax({ ...yourajaxhere... });             busy = false;  // put line in success() / error() callbacks         }, 500);     } else if (busy === false) {         cleartimeout(avail);         busy = true;         $.ajax({ ...yourajaxhere... });         busy = false;  // put line in success() / error() callbacks     } else {         return;     } }); 

this combine first 1 timeout waits .5 seconds , checks server availability. makes sure 1 check goes @ time quick mock want fine-tune situation.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -