等到重定向完成

i was wondering if it was possible in jquery\javascript to wait until redirects are done before firing the callback function.

My code looks something like below, everything is fine up to the callback for the post to login the user, when the verification is complete, the page gets redirected unfortunately at that point, the post request fires up the success callback function hence I end up getting the "Page redirecting.." instead of the page it is suppose to redirect to.

$(document).ready(function(){   
    $("#submit").click(function(){
        var url = "https://domain/login";

        $.ajax({
            url: url,
            type: "GET",
            dataType: "html",
            success: onGetFormSuccess,
            error: function(data) {
                alert('failed.');
            }
        });
    }); 

    function onGetFormSuccess(data) {
        var url = "https://domain/login";
        var parser = new DOMParser();
        doc = parser.parseFromString(data, "text/html");

        var inputs = doc.getElementById("formid").getElementsByTagName("input");
        var params = new Object();

        for (var i = 0; i < inputs.length; i++) {               
            if (inputs[i].name == "user")
                params[inputs[i].name] = $("#username").val();
            else if (inputs[i].name == "pass")
                params[inputs[i].name] = $("#password").val();
            else 
                params[inputs[i].name] = inputs[i].value;
        }

        $.ajax({
            url: url,
            type: "POST",
            data: params,
            success: onLoginSuccess,
            error: function(data) {
                alert('failed.');
            }
        });
     }

     function onLoginSuccess(data) {
         alert(data);
     }
});