Vinu
Vinu

Reputation: 167

Uncaught TypeError: Cannot read property 'success' of null in ajax

I have made a form validation using ajax post method. But i got the error "Uncaught TypeError: Cannot read property 'success' of null"...Can anybody help me to solve this...?

My Code

$.post("register.php",{uname:uname,pwd:pwd,cfmpwd:cfmpwd,email:email,gender:gender}).success(function(data){


        var obj = jQuery.parseJSON(data);
        $('.chatregalert').fadeIn('slow');
        if(obj.success == 1){
            $('.chatregalert').css('color','#067800');
            $('.chatuname').val('');
            $('.chatpwd').val('');
            $('.chatcfmpwd').val('');
            $('.chatemail').val('');
            $('.chatgender').val('');
        }else{
            $('.chatregalert').css('color','#CC0000');
        }
        $('.chatregalert').html(obj.msg);


    });
    return false;
});

I have tried alert(data) for success...It alert an empty box... How can i fix this..?

Upvotes: 0

Views: 3509

Answers (2)

Vinu
Vinu

Reputation: 167

Finally i got the solution. The problem is my server doesn't support JSON because the version of my PHP is 5.1.6. The JSON support available only PHP 5.2 and higher versions..

Upvotes: 1

N. Hodin
N. Hodin

Reputation: 1056

Could you try to do it like this :

$.post("register.php",
       {uname:uname,pwd:pwd,cfmpwd:cfmpwd,email:email,gender:gender},
       function(data){
            var obj = jQuery.parseJSON(data);
            $('.chatregalert').fadeIn('slow');
            if(obj.success == 1){
                $('.chatregalert').css('color','#067800');
                $('.chatuname').val('');
                $('.chatpwd').val('');
                $('.chatcfmpwd').val('');
                $('.chatemail').val('');
                $('.chatgender').val('');
            }else{
                $('.chatregalert').css('color','#CC0000');
            }
            $('.chatregalert').html(obj.msg);
     });

Upvotes: 0

Related Questions