开发者

why this jQuery does not work in Chrome?

开发者 https://www.devze.com 2023-03-17 16:46 出处:网络
I have a page with a form. There is an input control I populate with the parameter email\'s value from the url.

I have a page with a form. There is an input control I populate with the parameter email's value from the url.

So, when the page is loaded, I automatically submit the form to mail chimp, like this:

 <script type="text/javascript">
        $(document).ready(function () {
            $('#mc-embedded-subscribe-form').submit();
            if ($("#previousUrl").val().indexOf('?') != -1) {
                window.location.replace($("#previousUrl").val() + '&emailRegistered=true#newsletterAnchor');
            }
            else {
                window.location.replace($("#previousUrl").val() + '?emailRegistered=true#newsletterAnchor');
            }
        });
    </script>

and immediately after submit, I do a redirect to previous url.

Well, all this works fine in Firefox (a popup for confirmation is also opened after submitting the form and the main page is redirected back to the previous one.

I do not understand why this does not work in Chrome. I mean, somehow the POST action is not finished, because no other popup is opened (altought this page is redirecting back to the initial one).

Can you suggest me a way to do the redirect when FOR SURE the POST has been done? (in this way I think will work in Chrome too)...

UPDATE:

Form's target is "_blank" so the script from mail chimp (that's where I do POST) opens a confirmation popup window.

UPDATE 2:

Tried with ajax but for some reason it does not do anything...

$(document).ready(function () {
            jQuery.ajax({
                url: $('#mc-embedded-subscribe-form').attr('action'),
                data: $('#mc-embedded-subscribe-form').serialize(),
                type: 'POST',
                success: function () {
                    if ($("#previousUrl").val().indexOf('?') != -1) {
                        w开发者_开发问答indow.location.replace($("#previousUrl").val() + '&emailRegistered=true#newsletterAnchor');
                    }
                    else {
                        window.location.replace($("#previousUrl").val() + '?emailRegistered=true#newsletterAnchor');
                    }
                }
            });
            return false;
    });


You're trying to submit a form and redirect to another page at the same time? You can't do that. You can only make one request at a time (without AJAX, that is).

0

精彩评论

暂无评论...
验证码 换一张
取 消