Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ajax check username

Posted on 2010-11-17
9
Medium Priority
?
426 Views
Last Modified: 2012-05-10
hello there,
I made a little registration form and a little tool to check for taken username like this

domain.com/registration/validate_json?username=user1

it would say if user taken or not..

my question is how can I implement that so when the person types the username from the website
it would check automatically if its taken or available from a different domain website..
0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:karthi4all
ID: 34162017
Hi,

Make jquery request along with username as parameter,  for the keyboard change event of the input box

e.g: ('#inpbox').onChange(function(){
//////ajax query
})

Then at the server side,check with database and return true or false depending on availability, returning means echo "true"(for php)

for the result to be processed right, make succes function in jquery ajax query and if it returns true, display it by change color of the inpbox with green color or your choice.
0
 
LVL 1

Author Comment

by:XK8ER
ID: 34162111
sounds good but a need help with the ajax function because I have never done that..
0
 
LVL 10

Expert Comment

by:mahome
ID: 34162226
Here's an example for the ajax function.
Documentation you will find here: http://api.jquery.com/jQuery.get/, or for other Ajax stuff http://api.jquery.com/category/ajax/.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:mahome
ID: 34162238
Hmm the code got lost:
$('#name').onChange(function() {
  var name = $('#name').val();
   $.get('domain.com/registration/validate_json', { username : name }, function(data) {
      if (data == 'taken') alert('username is already taken'); // or show hint box
   });
}

Open in new window

0
 
LVL 10

Expert Comment

by:mahome
ID: 34162255
Oh and keep in mind, that you can't do an ajax call to a foreign domain. You have to use a proxy if you want to do that: http://stackoverflow.com/questions/3287487/jquery-load-method-loading-foreign-domain
0
 
LVL 1

Author Comment

by:XK8ER
ID: 34162334
>>keep in mind, that you can't do an ajax call to a foreign domain

yeah thats my issue here... how exactly do I work with your ajax code and call it from a different domain?
0
 
LVL 2

Expert Comment

by:karthi4all
ID: 34162871
You have to write a service that calls your other domain within your server , access that code through ajax instead other domain, its called a proxy
0
 
LVL 2

Accepted Solution

by:
karthi4all earned 2000 total points
ID: 34162974
For example if ur server is A, and other domain which has to be called via ajax is B.

Write server side code in A to call ajax in B.(use curl)

call A with ajax code instead of B.

Hope this helps you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question