0

如果用户单击登录按钮,我有表单(注册和登录)和模式背景,它们会添加到页面中。我正在使用 jquery 通过 ajax 提交表单。

$.post("/login",{
    "ajax":true,
    "email":$("#popup-window #login-form-email").val(),
    "password":$("#popup-window #login-form-password").val()
    },function(response){
        console.log(response);

        if(response.message=="success"){
            if(response.user.type==1){
                        console.log(window);

                        // window.location = "http://www.whatever.com/admin";
                        window[0].ownerDocument.location.href="http://www.whatever.com/admin";
                    } 
            if(response.user.type==2) window[0].ownerDocument.location.href = "http://www.whatever.com/trades";
        }else{
                $("#popup-window #login-form").append("<div id='invalid-login'>Invalid Login</div>");
            }

    },"json");

一切正常,除了

window.location = "http://www.whatever.com/admin";

并且 window 对象不是我所期望的。通过它,我发现以下确实有效

window[0].ownerDocument.location.href="http://www.whatever.com/admin";

在我测试的所有内容中(IE7、IE8、IE9、chrome、firefox)。我不确定为什么会这样,或者这是否是正确的方法。

我对 javascript 和 DOM 比较陌生,我真的很想了解这里发生了什么。

4

1 回答 1

1

利用window.location.href = "http://www.whatever.com/admin";

于 2012-11-16T16:40:54.060 回答