lundi 21 novembre 2016

Why is "open in new tab" sending a GET request?

I have the following HTML tag

<a href="#" id="navBar_navBarInput_3_subNavDropdownInput_0_subNavLinkInput_0" onclick="redirectPost(4,'EntryData.aspx');">My Link</a>

The Javascript "redirectPost"

function redirectPost(id, url) {
            post(url, { id: id });
        }

function post(path, params, method) {
            method = method || "post";
            var form = document.createElement("form");
            form.setAttribute("method", method);
            form.setAttribute("action", path);

            for (var key in params) {
                if (params.hasOwnProperty(key)) {
                    var hiddenField = document.createElement("input");
                    hiddenField.setAttribute("type", "hidden");
                    hiddenField.setAttribute("name", key);
                    hiddenField.setAttribute("value", params[key]);

                    form.appendChild(hiddenField);
                }
            }

            document.body.appendChild(form);
            form.submit();
        }

Here's the deal: when I just click on the link, the page sends a regular POST request. But whenever I use "open in a new tab" option, it sends a GET request and this is a problem for me since I do some validations background.

Does anyone have any idea why it behaves this way?

Thank you!

Aucun commentaire:

Enregistrer un commentaire