1

我正在使用此处找到的解决方案: Javascript Post on Form Submit open a new window

我得到的代码打开了目标页面,就好像提交工作正常一样。当我查看表单本身时,所有隐藏字段都在那里,但目标看不到它们 - PHP 代码中的 $_REQUEST 为空。这是我创建视图的功能(从上面提到的帖子中大量窃取):

    function post_to_url(path, params, method) {
        method = method || "post"; // Set method to post by default if not specified.

        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", path);
        form.setAttribute("target", "formresult");

        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);

        window.open("", "formresult", '');

        form.submit();

        document.body.removeChild(form);
    }

这是电话:

    post_to_url("test.php", { "username": "shaleth", "action": "login" }, "post");

我必须错过一些简单的东西,但我看不到它。任何援助将不胜感激。

4

0 回答 0