Jump to content
php.lv forumi

Jquery keyup


Recommended Posts

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 by reiniger
Link to post
Share on other sites

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..

Link to post
Share on other sites

         $('#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 by reiniger
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...