Solved

ajax check username

Posted on 2010-11-17
9
417 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 6

Expert Comment

by:Codebot
ID: 34162236
0
 
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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

778 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