Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox redirect with post doesn't work

My script works fine under chrome, but not under Firefox. Firefox simply shows me a white screen. The redirection must happen with POST.

<!DOCTYPE html>
<html>
    <script type='text/javascript'>
        //<![CDATA[ 

        var redirect = function(url, method) {
            var form = document.createElement('form');
            form.method = method;
            form.action = url;
            form.submit();
        };

        redirect('/mywebservice/mainpage', 'post');

        //]]>
    </script>
</html>
like image 405
Istvanb Avatar asked Jul 20 '26 14:07

Istvanb


1 Answers

You can't submit a form that isn't part of the page.

Add document.body.appendChild(form); before you try to submit it.

You can't do that before the body exists though. Add a <body> start tag before the script. In future, also run your code through a validator.

like image 147
Quentin Avatar answered Jul 23 '26 06:07

Quentin