Solved

ajax check username

Posted on 2010-11-17
9
416 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
Comment Utility
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
Comment Utility
sounds good but a need help with the ajax function because I have never done that..
0
 
LVL 10

Expert Comment

by:mahome
Comment Utility
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
 
LVL 6

Expert Comment

by:Codebot
Comment Utility
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:mahome
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now