$ .ajax成功回调没有在firefox中触发

时间:2013-09-10 17:35:59

标签: javascript jquery ajax firefox cross-browser

我遇到了一个问题,即我对$ .ajax的调用成功完成并返回内容,其响应为200OK,如firebug所报告,但成功,完整和错误回调不会执行。这只发生在firefox中,在chrome中运行正常(我正在运行firefox22)。

$.ajax(site_url+url+'/fetch_salt',{type:'POST',data:data,success:check_salt});
var group = '';

function check_salt(d)
{
    console.log(d);

firebug报告的请求的实际响应是:

choose_login:{"admin":"Admin Zone"}

响应类型:

Content-Type    text/html

我已经尝试强制设置像dataType和contentType,以防jquery假设json或者其他东西我已经尝试过匿名函数来处理错误,成功和完整的回调,但没有任何作用。

我发布了完整的功能代码,以防万一它的某种语法错误:

function prep_login_form(elem,url,challenge)
{
    function show_error(msg)
    {
        $(elem).find('.ecms-error-for-password .ecms-error-text').html(msg).closest('.ecms-error-container').removeClass('ecms-error-hidden');
    }

    function submit()
    {
        var data = {email:$(elem).find('input[name="email"]').val()};
        data[csfr_token_name] = csfr_hash;
        $.ajax({type:'POST',url:site_url+url+'/attempt_login',data:data,success:check_salt});
        var group = '';

        function check_salt(d)
        {
            console.log(d);
            if (d=='no_email')
            {
                show_error('Invalid Email address');
            }
            else if (d=='account_disabled')
            {
                show_error('This account has been disabled, please contact your administrator');
            }
            else if (d.substr(0,12)=='choose_login')
            {
                var cl;
                eval('cl = '+d.substr(13));
                var cou = 0;
                for (p in cl)
                {
                    cou++;
                }
                if (cou==1)
                {
                    group = p;
                    var mydata = $.extend(data,{group:p});
                    $.ajax(site_url+url+'/fetch_salt',{type:'POST',data:mydata,success:check_salt})
                }
                else
                {
                    var str = '<div class="login-selection-popup"><p>We have detected that your email address is linked to more than one account.<br />Please select which zone you would like to login to.</p><ul class="choose-login-popup">';
                    for (p in cl)
                    {
                        str+='<li><a rel="'+p+'">'+cl[p]+'</a></li>';
                    }
                    str+='</ul></div>';
                    open_modal({heading:'Choose Account',content:str,buttons:function(close_modal)
                    {
                        $(this).find('.choose-login-popup').on('click','a',function()
                        {
                            group = $(this).attr('rel');
                            var mydata = $.extend(data,{group:$(this).attr('rel')});
                            $.ajax(site_url+url+'/fetch_salt',{type:'POST',data:mydata,success:check_salt})
                            close_modal();
                        });
                    }});
                }
            }
            else
            {
                var salt = d;
                var pw = $(elem).find('input[name="password"]').val();
                data.password = hex_md5(challenge+hex_md5(salt+pw));
                data.group = group;
                $.ajax(site_url+url+'/attempt_login',{type:'POST',data:data,success:function(d)
                {
                    if (d=='no_email')
                    {
                        show_error('Invalid username or password');//Invalid Email address
                    }
                    else if (d=='account_disabled')
                    {
                        show_error('This account has been disabled, please contact your administrator');
                    }
                    else if (d=='invalid_login')
                    {
                        show_error('Invalid username or password');//Email or Password did not match
                    }
                    else
                    {
                        window.location.href = d;
                    }
                }});
            }
        }
    }

    $(elem).on('keyup','input',function(e)
    {
        if (e.keyCode=='13')
        {
            submit();
        }
    });
    $(elem).find('.login-submit').on('click',function()
    {
        submit();
    });
}

1 个答案:

答案 0 :(得分:0)

抱歉,我最近在我的电脑上添加了一些麻烦并且为了摆脱它而奋斗。我认为它已经损坏/劫持了我的Firefox。重新安装firefox后,问题就消失了,回调现在就会执行。