Abhinav Singh
Abhinav Singh

Reputation: 31

$.ajax() success and error not getting called

$.ajax({
    url: "captcheck.php",
    type: "GET",
    data: "code="+captcha.val(),        
    cache: false,
    success: function (html) {              
        if (html==1) {  
            captcha.removeClass('validation-error',animateSpeed);
            return true;
        } 
        else {
            captcha.addClass('validation-error',animateSpeed);
            return false;
        }    
    },      
    error: function(httpRequest, textStatus, errorThrown) { 
        alert("status=" + textStatus + ",error=" + errorThrown);
    }
});

Now this is a pretty simple ajax function, but neither is its success getting called nor error, i checked the XHR with response on the firebug and its perfect, still neither success nor error getting called. Can anyone please help?

Upvotes: 3

Views: 2415

Answers (2)

ChuanRocks
ChuanRocks

Reputation: 1528

There is no way I can test your code on my end, but I will give my two cents:

  • Add the 'complete' callback function to help you figure out if there is any syntax errors in your code.. From jQuery document: "'Complete' is a function to be called when the request finishes (after success and error callbacks are executed)"

  • Use simple codes like alert('str') and console.log('str') inside callback functions for debugging.

Btw, do addClass and removeClass support more than one parameter? I can't find it in the official document.

Upvotes: 2

Vodun
Vodun

Reputation: 1385

Maybe it's the if (html==1) since success callback return string, you should try if (html==="1")

Upvotes: 0

Related Questions