用post数据格式重定向到PHP页面


Redirecting to PHP page with post data format

我在stackoverflow上看过很多帖子,但我找不到我的答案,所以这就是我在这里发帖的原因。场景是这样的:我的页面有许多div容器,每个div都有编辑按钮,当用户单击任何div的编辑时,我希望用户被重定向到另一个具有该DIV ID的页面,我想用POST方法来解决这个问题。文件edit。

<button class="edit_btn" onclick="edit_ID('$btn_id')">
<script type="text/javascript">

      function edit_ID(array){
        $.ajax({    type:"POST",
                    url:'redirecter.php',
                    data:{editorID:array.split("_")[1]},
                    success:function(data){
                        //window.location.href="editapplication.php";
                    }
                });
      }
</script>
文件redirector.php

<form action='editapplication.php' method='post' name='frm'>
<?php
foreach ($_POST as $a => $b) {
echo "<input type='hidden' name='".htmlentities($a)."' value='".htmlentities($b)."'>";
}
?>
</form>
<script language="JavaScript" type="text/JavaScript">
document.frm.submit();
</script>

你需要钩住按钮的click事件,并在那里执行你的操作:

$(function() {
    $('#buttonID').bind('click', function(event){
      var id = $(this).parent().id;
      $.ajax({....});
    });
});