Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

how to check if a username is available without refreshing using php and ajax?

OpenStudy (anonymous):

can you explain your problem?

OpenStudy (anonymous):

do you mean, check to see if it is available to register? or if it already exists? Both will need php to connect to an sql database where the username info is kept. My best advice is learn the php to sql part of checking for the username. Then use ajax to do it asynchronously.

OpenStudy (anonymous):

Your question is a bit vague, exactly what do you need? an overview, actual code?

OpenStudy (mattfeury):

You'll need to set up a php script that handles POST requests (just like any other form) and prints out JSON. Make sure you've declared valid file header: header('Content-type: application/json'); and then echo json echo json_encode(array("valid_username" => $isValidUsername)) that's just the server side of things. You'll want to handle the response with javascript, checking the response.valid_username field and handling appropriately. You may want to look at frameworks like jQuery (jQuery.com) for really making AJAX calls smooth as ice.

OpenStudy (anonymous):

Open the registration page in a new tab and try your username?

OpenStudy (anonymous):

yes, what i mean is check if that username was avalailable on database, so the user that want to register on my site can choose another username... thanks for the reply :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!