복붙노트

[JQUERY] 자바 스크립트 / jQuery를 함께 리디렉션에 POST 데이터를 전송? [복제]

JQUERY

자바 스크립트 / jQuery를 함께 리디렉션에 POST 데이터를 전송? [복제]

해결법


  1. 1.구축 및 숨겨진 방법 = POST 액션 = "http://example.com/vote를"양식을 작성하고 오히려 전혀에서는 window.location을 사용하는 것보다, 그것을 제출합니다.

    구축 및 숨겨진 방법 = POST 액션 = "http://example.com/vote를"양식을 작성하고 오히려 전혀에서는 window.location을 사용하는 것보다, 그것을 제출합니다.


  2. 2.당 @ 케빈 - 리드의 대답은 여기에 대한 대안 년대을 피가 이름을 지정하고 다음 (jQuery를 사용하여) 특별히 양식을 구성하여 다시 양식 객체를 조회 할 필요가 있음을 예를 들어 "나는 다음을 수행 결국"..

    당 @ 케빈 - 리드의 대답은 여기에 대한 대안 년대을 피가 이름을 지정하고 다음 (jQuery를 사용하여) 특별히 양식을 구성하여 다시 양식 객체를 조회 할 필요가 있음을 예를 들어 "나는 다음을 수행 결국"..

    var url = 'http://example.com/vote/' + Username;
    var form = $('<form action="' + url + '" method="post">' +
      '<input type="text" name="api_url" value="' + Return_URL + '" />' +
      '</form>');
    $('body').append(form);
    form.submit();
    

  3. 3.다음은 jQuery를 사용하고 같이 어디만큼 적용 할 수있는 간단한 작은 기능입니다.

    다음은 jQuery를 사용하고 같이 어디만큼 적용 할 수있는 간단한 작은 기능입니다.

    var redirect = 'http://www.website.com/page?id=23231';
    $.redirectPost(redirect, {x: 'example', y: 'abc'});
    
    // jquery extend function
    $.extend(
    {
        redirectPost: function(location, args)
        {
            var form = '';
            $.each( args, function( key, value ) {
                value = value.split('"').join('\"')
                form += '<input type="hidden" name="'+key+'" value="'+value+'">';
            });
            $('<form action="' + location + '" method="POST">' + form + '</form>').appendTo($(document.body)).submit();
        }
    });
    

  4. 4.당신이 jQuery를 사용하는 경우, POST 또는 GET 방식과 그 작품 플러그인 리디렉션이있다. 그것은 숨겨진 입력으로 양식을 작성하고 당신을 위해 그것을 제출합니다. 어떻게 작업을 얻을 수의 예 :

    당신이 jQuery를 사용하는 경우, POST 또는 GET 방식과 그 작품 플러그인 리디렉션이있다. 그것은 숨겨진 입력으로 양식을 작성하고 당신을 위해 그것을 제출합니다. 어떻게 작업을 얻을 수의 예 :

    $.redirect('demo.php', {'arg1': 'value1', 'arg2': 'value2'});
    

    참고 : 선택 사양 인 세 번째 매개 변수로 메소드 유형 GET 전달하거나 게시 할 수 있습니다; POST가 기본값입니다.


  5. 5.여기에 jQuery를 사용하지 않는 방법이다. 나는 북마크, W3-HTML-검증에 확인 현재 페이지를 만드는 데 사용했다.

    여기에 jQuery를 사용하지 않는 방법이다. 나는 북마크, W3-HTML-검증에 확인 현재 페이지를 만드는 데 사용했다.

    var f = document.createElement('form');
    f.action='http://validator.w3.org/check';
    f.method='POST';
    f.target='_blank';
    
    var i=document.createElement('input');
    i.type='hidden';
    i.name='fragment';
    i.value='<!DOCTYPE html>'+document.documentElement.outerHTML;
    f.appendChild(i);
    
    document.body.appendChild(f);
    f.submit();
    

  6. 6.난 당신에게 내가 함께 일하고있는 샘플 코드를 제공합니다, 그래서 여기에 대한 답은 혼란 스러울 수 있습니다.

    난 당신에게 내가 함께 일하고있는 샘플 코드를 제공합니다, 그래서 여기에 대한 답은 혼란 스러울 수 있습니다.

    당신이 언급하는 것을 자바 스크립트 windows.location 기능에는 POST 매개 변수가 없음을 메모와 함께 시작합니다.

    그래서 당신은해야 ...

    그리고 예를 들어.

         //---------- make sure to link to your jQuery library ----//
    
    <script type="text/javascript" >
    
        var form = $(document.createElement('form'));
        $(form).attr("action", "test2.php");
        $(form).attr("method", "POST");
        $(form).css("display", "none");
    
        var input_employee_name = $("<input>")
        .attr("type", "text")
        .attr("name", "employee_name")
        .val("Peter" );
        $(form).append($(input_employee_name));
    
    
        var input_salary = $("<input>")
        .attr("type", "text")
        .attr("name", "salary")
        .val("1000" );
        $(form).append($(input_salary));
    
        form.appendTo( document.body );
        $(form).submit();
    
    </script>
    

    모두가 잘되면, 당신은 test2.php로 리디렉션되어야하며, 당신은 EMPLOYEE_NAME 급여의 전달 된 값을 읽을 POST를 사용할 수 있습니다; 즉, 피터 1000을 각각됩니다.

    test2.php에서 당신은 따라서 귀하의 값을 얻을 수 있습니다.

    $employee_name = $_POST['employee_name'];
    $salary = $_POST['salary'];
    

    말할 필요도없이, 당신이 전달 된 값을 소독해야합니다.


  7. 7.일반 함수는 주어진 URL에 대한 자바 스크립트 객체를 작성합니다.

    일반 함수는 주어진 URL에 대한 자바 스크립트 객체를 작성합니다.

    function postAndRedirect(url, postData)
    {
        var postFormStr = "<form method='POST' action='" + url + "'>\n";
    
        for (var key in postData)
        {
            if (postData.hasOwnProperty(key))
            {
                postFormStr += "<input type='hidden' name='" + key + "' value='" + postData[key] + "'></input>";
            }
        }
    
        postFormStr += "</form>";
    
        var formElement = $(postFormStr);
    
        $('body').append(formElement);
        $(formElement).submit();
    }
    

  8. 8.이 사용하기에 매우 편리합니다 :

    이 사용하기에 매우 편리합니다 :

    var myRedirect = function(redirectUrl, arg, value) {
      var form = $('<form action="' + redirectUrl + '" method="post">' +
      '<input type="hidden" name="'+ arg +'" value="' + value + '"></input>' + '</form>');
      $('body').append(form);
      $(form).submit();
    };
    

    다음을 같이 사용합니다 :

    myRedirect("/yourRedirectingUrl", "arg", "argValue");
    

  9. 9.

    var myRedirect = function(redirectUrl) {
    var form = $('<form action="' + redirectUrl + '" method="post">' +
    '<input type="hidden" name="parameter1" value="sample" />' +
    '<input type="hidden" name="parameter2" value="Sample data 2" />' +
    '</form>');
    $('body').append(form);
    $(form).submit();
    };
    

    http://www.prowebguru.com/2013/10/send-post-data-while-redirecting-with-jquery/에서 코드 발견

    내 작품이 다른 제안을 시도하는 것.

    동일한 작업을 수행 할 수있는 다른 방법이 있나요?


  10. 10.당신은 iframe에서 리디렉션과 양식을 보낼 대상 속성을 사용할 수 있습니다. 양식 열린 태그는 다음과 같이 될 것이다 :

    당신은 iframe에서 리디렉션과 양식을 보낼 대상 속성을 사용할 수 있습니다. 양식 열린 태그는 다음과 같이 될 것이다 :

    method="post" action="http://some.url.com/form_action" target="_top"
    

  11. 11.そぅちおん의. 1

    そぅちおん의. 1

     //your variable
        var data = "brightcherry";
    
        //passing the variable into the window.location URL
        window.location.replace("/newpage/page.php?id='"+product_id+"'");
    

    そぅちおん의. 2

    //your variable
    var data = "brightcherry";
    
    //passing the variable into the window.location URL
    window.location.replace("/newpage/page.php?id=" + product_id);
    

    세부

  12. from https://stackoverflow.com/questions/8389646/send-post-data-on-redirect-with-javascript-jquery by cc-by-sa and MIT license