1

我遇到了一个问题,我对 $.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();
    });
}
4

1 回答 1

0

对不起,我最近在我的电脑上安装了附加软件并努力摆脱它。我认为它损坏/劫持了我的 Firefox。重新安装 firefox 后问题消失了,现在执行回调。

于 2013-09-11T16:15:27.393 回答