1

I try to use the next example to checking username availability but I can't receive the result of .post that I want.

http://web.enavu.com/tutorials/checking-username-availability-with-ajax-using-jquery/

In the next code, the alert() show me the .php file, but I just want 0 or 1 in order to know if the user exist or not:

    //use ajax to run the check
    $.post("check_username.php", { username: username },
        function(result){ alert(result);
            //if the result is 1
            if(result == 1){
                //show that the username is available
                $('#username_availability_result').html(username + ' is Available');
            }else{
                //show that the username is NOT available
                $('#username_availability_result').html(username + ' is not Available');
            }
    });

Thanks a lot!

4
  • What does the alert say? Commented Oct 4, 2011 at 13:09
  • It shows the .php file, all the code in the alert() window. Commented Oct 4, 2011 at 13:12
  • after var username = $('#username').val(); alert(username) and check what is the value you are sending. Also what is the alert you get after the post ? Commented Oct 4, 2011 at 13:13
  • alert(username) show the user of the <input type='text' id='username'>. Commented Oct 4, 2011 at 13:19

1 Answer 1

1

Where are you hosting your php file? Inside apache? If you are getting the full contents of php file then most probably you have not deployed it correctly.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm using in localhost a WampServer. What is your advice? :)
Try to call the php file using your browser's address and see what is being returned. For example localhost/MYAPPNAME/check_username.php if you are still getting contents of the file then it is really a server issue.
@Shamaila Tahir I didn't put the file in the good place for apache. Now I have a sql error, thanks, I try to fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.