开发者

Any reason why my $.ajax success callback is not executed in Jquery?

Today i discovered that my dev version of my website do not execute success callback, but all other javascript and jquery code is running good. Even my ajax request is performed and i can see response in firebug.

$('#login').submit(function(){
    var emai开发者_Go百科l = $('#l_email').val();
    var pass = $('#l_pass').val();
    if(email && pass != ''){
        var str = decodeURIComponent($(this).serialize());
        $.ajax({
            type: "POST",
            url: "login.php",
            data: str,
            success: function(msg){
                if(msg == 'OK'){
                    window.location = 'index.php'
                }else if (msg == 'NOT_OK'){
                    if(lang == 'lv'){
                        alert(message);
                    }else if(lang == 'ru'){
                        alert(message);
                    }
                }else if (msg == 'EMAIL_NOT_VALID'){
                    if(lang == 'lv'){
                        alert(message);
                    }else if(lang == 'ru'){
                        alert(message);
                    }      
                }
            }
         });
    }else{
        alert('That form is empty.');
    }
    return false;
});

The thing is $.ajax part executes fine and i can see response in firebug "OK". But redirect is not happening and even if i replace that redirect with something like alert or console.log nothing comes up.

What could cause this? It's really hard to track since firebug gives no errors.

Resolved: by suggestion of Reigel, wrapping success callback data return in $.trim();


How about adding an else { alert('No match for msg'); } block to the code of your success function, maybe you'll see that msg does not match any of your IFs statements.

jQuery doc says the signature of the success function should be: success(data, textStatus, XMLHttpRequest) so I guess msg if not getting the response status but rather the data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜