PHP Ajax

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
vivekjain
Forum Commoner
Posts: 76
Joined: Thu Jan 08, 2004 12:38 am

PHP Ajax

Post by vivekjain »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
 I am developing an application using PHP. There is a form where the users need to enter their info. They also enter an username, and on clicking the submit button, we are using Ajax to validate for the username, i.e. the username needs to be a unique one. When I submit the page, within the Javascript function, we are calling another javascript function which handles the Ajax functionality of checking for the username. The function returns the result. Now, the problem that I am facing here is, the first time when I submit I am not getting the correct result, but the next time I click submit it works fine. 

This is the code [syntax="javascript"]
showHint(document.form1.username.value);
flag_username =(document.getElementById("txtHint").innerHTML)

function showHint(str, ref)
{
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)

} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	
	document.getElementById("txtHint").innerHTML=xmlHttp.responseText
	} 
} 

So the first time when I click the Submit button, after this is executed "xmlHttp.send(null)", it comes back to the first Js function, and then the StateChanged function. But the second time it works fine.

Can anyone suggest me a solution to this?
Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply