Programming

POST 양식을 제출 한 후 결과를 보여주는 새 창을 엽니 다

procodes 2020. 6. 12. 23:18
반응형

POST 양식을 제출 한 후 결과를 보여주는 새 창을 엽니 다


양식 제출과 같은 JavaScript 게시물 요청 은 JavaScript에서 POST를 통해 작성한 양식을 제출하는 방법을 보여줍니다. 아래는 수정 된 코드입니다.

var form = document.createElement("form");

form.setAttribute("method", "post");
form.setAttribute("action", "test.jsp");

var hiddenField = document.createElement("input");  

hiddenField.setAttribute("name", "id");
hiddenField.setAttribute("value", "bob");
form.appendChild(hiddenField);
document.body.appendChild(form); // Not entirely sure if this is necessary          
form.submit();

내가하고 싶은 일은 새 창에서 결과를 여는 것입니다. 현재 새 창에서 페이지를 열기 위해 다음과 같은 것을 사용하고 있습니다.

onclick = window.open(test.html, '', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

더하다

<form target="_blank" ...></form>

또는

form.setAttribute("target", "_blank");

양식의 정의에 따라


질문에있는 것처럼 Javascript에서 양식을 작성하고 제출하고 사용자 정의 기능을 사용하여 팝업 창을 작성하려면이 솔루션을 제안합니다 (추가 한 행 위에 주석을 넣습니다).

var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "test.jsp");

// setting form target to a window named 'formresult'
form.setAttribute("target", "formresult");

var hiddenField = document.createElement("input");              
hiddenField.setAttribute("name", "id");
hiddenField.setAttribute("value", "bob");
form.appendChild(hiddenField);
document.body.appendChild(form);

// creating the 'formresult' window with custom features prior to submitting the form
window.open('test.html', 'formresult', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

form.submit();

var urlAction = 'whatever.php';
var data = {param1:'value1'};

var $form = $('<form target="_blank" method="POST" action="' + urlAction + '">');
$.each(data, function(k,v){
    $form.append('<input type="hidden" name="' + k + '" value="' + v + '">');
});
$form.submit();

이 기본 방법을 알고 있습니다.

1)

<input type=”image” src=”submit.png”> (in any place)

2)

<form name=”print”>
<input type=”hidden” name=”a” value=”<?= $a ?>”>
<input type=”hidden” name=”b” value=”<?= $b ?>”>
<input type=”hidden” name=”c” value=”<?= $c ?>”>
</form>

삼)

<script>
$(‘#submit’).click(function(){
    open(”,”results”);
    with(document.print)
    {
        method = “POST”;
        action = “results.php”;
        target = “results”;
        submit();
    }
});
</script>

공장!


흐름 창을위한 가장 간단한 작업 솔루션 (Chrome에서 테스트) :

<form action='...' method=post target="result" onsubmit="window.open('','result','width=800,height=400');">
    <input name="..">
    ....
</form>

참고 URL : https://stackoverflow.com/questions/178964/after-submitting-a-post-form-open-a-new-window-showing-the-result

반응형