View Single Post
Old 01-29-2012, 04:18 PM   PM User | #1
jackvan
New Coder

 
Join Date: Jan 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
jackvan is an unknown quantity at this point
Not getting any data from Ajax success response

I'm learning how to do Ajax with Jquery to validate a Form.

First it checks the format of the username to see if it is an valid format, if the format is correct than use Jquery Ajax to check a script to see if the username is available or not.

Here are the Ajax portion of the code:

PHP Code:

$.ajax({
    
url:"username_check_script_url",
    
async:false,
    
success:function(data){
        
alert("data");
        return 
true;
        }
}); 
When the above Script was run, it can get into the success:function(data) loop, but it will not return the data from the
username_check_script_url??

The followings is a test script to illustrate the problem:

PHP Code:
    function validateName(){
        
//if it's NOT valid
        
if(name.val().length 4){
            
alert("We want names with more than 3 letters!");
            return 
false;
        }
        
//if it's valid, check name available or not
        
else{
            
                $.
ajax({
                
url:"ajax.txt",
                
async:false,
                
success:function(data){
                    
alert("data");
                    return 
true;
                    }
            });
            return 
true;
        }
    } 
"ajax.txt" has the words: "OK to use"

The intention of the script is if I enter a name with more than 3 letters, it will fetch "ajax.txt", then return the data in "ajax.txt" which is "OK to use" and shows in the alert message.

But when I enter "abcd" in the Form, I get a pop-up warning message: "data" instead of "OK to use"??

It appears that Ajax communicated with "ajax.txt", but when it gets into the success:function(data){ loop, it is not returning the data from the "ajax.txt"?

Kindly help to explain what I did wrong and how to fix the problem?

Thanks
jackvan is offline   Reply With Quote