After I'm done with Ajax redirect the right wi

2019-09-18 18:20发布

问题:

I was implementing my code from this answer to do Ajax calls in webkit on a form upload and it works well. https://stackoverflow.com/a/16200886/548558

My backend gives me a redirect if the form is valid but the redirect is happen in the iframe but I really want to have it the normal window. How I can do this? Anybody has an idea?

CODE

$(function() {
    $('#upload-form').submit(function() {
        // Prevent multiple submits
        if ($.data(this, 'submitted')) return false;
        $(this).prop("target", "file-upload");
        // Update progress bar
        function update_progress_info() {
            // $progress.show();
            $.getJSON(progress_url, {'X-Progress-ID': uuid}, function(data, status) {
                if (data) {
                    var progress = parseInt(data.uploaded) / parseInt(data.length);
                    var width = $progress.find('.progress-container').width()
                    var progress_width = width * progress;
                    $progress.find('.progress-bar').width(progress_width);
                    $progress.find('.progress-info').text('uploading ' + parseInt(progress*100) + '%');
                    console.log("progress")
                    console.log(progress)
                    window.setTimeout(update_progress_info, freq);
                }
            });
        };
        window.setTimeout(update_progress_info, freq);

        $.data(this, 'submitted', true); // mark form as submitted
    });
});

回答1:

If your call, if I understood your question, is made into an iframe, you must go to your window component, call to his parent (the container of this iframe) and call his methods location and href. I had to use this a few time ago and worked for me.

window.parent.location.href = "/foo.html"



标签: jquery forms