Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX making 3 requests? 2

Status
Not open for further replies.

snowboardr

Programmer
Joined
Feb 22, 2002
Messages
1,401
Location
PH
I am wondering if i am doing something wrong, because firebug is telling me that the ajax script below is making three requests... Also note, that my timer is so when the user stops typing then the timer starts when the timer fires then it runs... this way it doesn't fire every moment they are typing.... When they press a key the timer is killed...

Jason

Code:
var CheckUserNameHTTP = null;
function CheckUserName() {
	
	  clearTimeout(CheckUserNameTimer);
		showhide('loading');
		var strUserName = document.getElementById('frmUserName').value;
	if (strUserName != "") {
		CheckUserNameHTTP = createRequestObject();
		var url5="/ajax/mail/username_check.asp?username=" + strUserName;
		CheckUserNameHTTP.open('GET', url5, true);
		CheckUserNameHTTP.onreadystatechange = checkUserNameDone;
		CheckUserNameHTTP.send('');
	}
}

function checkUserNameDone() {
	if (CheckUserNameHTTP.readyState == 4 || CheckUserNameHTTP.readyState=="complete") {
	  showhide('loading');
	  document.getElementById('notify').innerHTML = CheckUserNameHTTP.responseText;
   }
}

var CheckUserNameTimer=null;
function startCheckUserNameTimer() {
	CheckUserNameTimer = setTimeout('CheckUserName()',1650);
}

function endCheckUserNameTimer() {
	clearTimeout(CheckUserNameTimer);
}

Army : Combat Engineer : 21B

 
I thought you had to do that to kill it?

Code:
var CheckUserNameTimer=null;
function startCheckUserNameTimer() {
    CheckUserNameTimer = setTimeout('CheckUserName()',1650);
}

function endCheckUserNameTimer() {
    clearTimeout(CheckUserNameTimer);
}

Army : Combat Engineer : 21B

 

I am calling it here

setTimeout('CheckUserName()',1650);

Code:
<input name="frmUserName" type="text" id="frmUserName" onkeyup="startCheckUserNameTimer();" onkeydown="endCheckUserNameTimer();"/>

Army : Combat Engineer : 21B

 
try using only onkeyup or onkeydown (or onkeypress). that would mean your function would change to:

Code:
var CheckUserNameTimer;

function startCheckUserNameTimer() {
    clearTimeout(CheckUserNameTimer);
    CheckUserNameTimer = setTimeout('CheckUserName()',1650);
}

(you could get rid of the clearing function.)

do you have a link to this?



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
that works perfect, thanks Cory! I don't have it live yet because i have to do a bunch of stuff to upload it, but ill let you know when it is...


Here is some screenshot (its like gmail but for website mail) for a project i am doing for a hobby...




Army : Combat Engineer : 21B
 
Star for you Cory!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top