reiniger Posted July 26, 2010 Report Share Posted July 26, 2010 (edited) Nepieciešams lai ievadot tekstu ja tāds jau eksistē parāditos paziņojums. Es izmantoju šādu kodu $(document).ready(function() { var timeOut = null; // this used for hold few seconds to made ajax request var loading_html = 'Check ...'; // just an loading image or we can put any texts here //when button is clicked $('#username').keyup(function(e){ if (timeOut != null) clearTimeout(ajaxCallTimeoutID); timeOut = setTimeout(is_available, 1000); // delay delay ajax request for 1000 milliseconds $('#user_msg').html(loading_html); // adding the loading text or image }); }); function is_available(){ //get the username var username = $('#username').val(); //make the ajax request to check is username available or not $.post("check.php", { username: username }, function(result) { if(result != 0) { $('#user_msg').html('Not Available'); } else { $('#user_msg').html('<span style="color:#006600;">Available</span>'); } }); } Apstrada: <?php //data connection file include("connect_server.php"); $username = mysql_real_escape_string($_POST['username']); $result = mysql_query('select Client from ClientRef where Client = "'. $username .'"'); $cnt = mysql_num_rows($result); print($cnt); ?> šis kods nostrādā tikai uz vienu pogas nospiedienu un visu laiku rada ka ir derīgs teksts. Ja uzreiz iekopē visu vārdu tad atpazīst ka jau tāds eksistē. Kā panākt lai pārbaude notiek pēc katra spiediena? Edited July 26, 2010 by reiniger Quote Link to comment Share on other sites More sharing options...
briedis Posted July 26, 2010 Report Share Posted July 26, 2010 Kur šitais rodās? ajaxCallTimeoutID Principā jau vajadzētu strādāt, bet ja nē, tad derēt arī debugot kodu, vispār.. Quote Link to comment Share on other sites More sharing options...
Леший Posted July 26, 2010 Report Share Posted July 26, 2010 'check.php?rnd='+Math.random() Quote Link to comment Share on other sites More sharing options...
reiniger Posted July 26, 2010 Author Report Share Posted July 26, 2010 'check.php?rnd='+Math.random() šo kodu neta atradu, ar šo labojumu ar nekas nemainijas. Tikai parbaude notiek pie pirmas ievades. Quote Link to comment Share on other sites More sharing options...
101111 Posted July 26, 2010 Report Share Posted July 26, 2010 paskaties vai shitaa straadaa $('#username').keyup(function(e){ is_available(); $('#user_msg').html(loading_html); // adding the loading text or image }); Quote Link to comment Share on other sites More sharing options...
reiniger Posted July 26, 2010 Author Report Share Posted July 26, 2010 paskaties vai shitaa straadaa $('#username').keyup(function(e){ is_available(); $('#user_msg').html(loading_html); // adding the loading text or image }); Šitais strādā. Paldies... Quote Link to comment Share on other sites More sharing options...
briedis Posted July 26, 2010 Report Share Posted July 26, 2010 Jā, bet tas nav labs risinājums! Tomēr, vajag nelielu taimautu, jo šinī gadījumā pēc katra taustiņa tiks izsaukts pieprasījums. Vajadzētu nogaidīt kādu sekundīti, kad beidz rakstīt, tad pārbaudīt.. Quote Link to comment Share on other sites More sharing options...
reiniger Posted July 26, 2010 Author Report Share Posted July 26, 2010 (edited) $('#username').keyup(function(e){ if (this.timer) clearTimeout(this.timer); this.timer = setTimeout(function () { is_available(); $('#user_msg').html(loading_html); // adding the loading text or image }, 1000); }); Nu tad es izveidoju lai nedaudz aizture ira. Edited July 26, 2010 by reiniger Quote Link to comment Share on other sites More sharing options...
briedis Posted July 26, 2010 Report Share Posted July 26, 2010 Zolīdi :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.