使用jQuery在表单提交(post)之前取消设置php变量


Unset php variables before form submit (post) using jQuery

我有两个变量$get_book_id$_GET['book_id']以及一个发布其他数据的表单。当点击提交按钮时,我想清空上面的两个变量,并使用表单发布剩余的值。

jquery代码如下所示。

index.php

    $('#submit_button').click(function(){
                $.ajax({
                type: 'POST',
                url: 'empty_variable.php',
                success: function(data) { 
                },
                error: function(ts) { alert(ts.responseText) }
            });
    });
    <form action="process.php" method="post">
            .................
    </form>

empty_variable.php

    <?php
    $get_book_id = '';
    $_GET['book_id'] = '';
    ?>

process.php

<?php 
echo $_GET['book_id'];
echo $get_book_id;
print_r($_POST);    
?>

我想做的是,在表单提交时使用jQuery清空两个变量。我该怎么做
在流程页面中,我仍然可以看到$_GET值和$get_book_id

请不要让我清空index.php页面中的值。

使用jQuery在表单提交(发布)前取消设置php变量

感谢

Kimz

更新答案,使用post请求,如果字段为空,则将变量设置为空:

将提交输入更改为如下按钮:index.php

<script type="text/javascript">
    $(document).ready(function() {
         $('#submit_button').on('click', function(e) {
              $('#book_id').val('');
              $(this).submit();                     
         });
    });                       
</script>
<form id="form_id" action="process.php" method="POST">
    <input id="book_id" name="book_id" type="text" />
    <button id="submit_button">Submit</button>
</form>

process.php

if($_POST['book_id'] = '') $get_book_id = $_POST['book_id'];
echo $_POST['book_id'];
echo $get_book_id;
print_r($_POST);

尝试这种方式

 $('#submit_button').click(function(){
            $.ajax({
            type: 'POST',
            data:{"clearBit":"YES"},  //use the data to refresh the specified variables on process.php page
            url: 'empty_variable.php',
            success: function(data) { 
            },
            error: function(ts) { alert(ts.responseText) }
        });
});

Process.php:

 <?php
   if(isset($_POST['clearBit']) && $_POST['clearBit']=='YES')
   {
     $get_book_id = '';
     $_GET['book_id'] = '';
   }    
?>

快乐编码:)