• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

ajax check username

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
XK8ER
Asked:
XK8ER
  • 3
  • 3
  • 2
  • +1
1 Solution
 
karthi4allCommented:
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
 
XK8ERAuthor Commented:
sounds good but a need help with the ajax function because I have never done that..
0
 
mahomeCommented:
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
Industry Leaders: 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!

 
mahomeCommented:
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
 
mahomeCommented:
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
 
XK8ERAuthor Commented:
>>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
 
karthi4allCommented:
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
 
karthi4allCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now