$.post 呼び出しにシリアル化されたフォームと共に 2 つの変数を含めようとしましたが、それを行う唯一の方法は、serialize() ではなく serializeArray() を使用し、余分な変数を配列。すべてのフォーム要素は正しく処理されていますが、余分な 2 つの変数 (order と column) は処理されていません。
JQ:
var order = 'asc';
var column = 'description';
$('#task_form').submit(function(e){
var formData = $("#task_form").serializeArray();
formData.push({column: column, order: order});
$.post('process.php', formData, function(data){
// clear the current task table
$('#tbody').empty();
// refresh the task table with the newly inserted task
$(data).appendTo('#tbody');
$('#tasks_table').trigger('update');
$("#description_text").val('');
});
e.preventDefault();
});
PHP:
if(isset($_POST['description_text'])){
$description = $_POST['description_text'];
$duration = $_POST['duration_text'];
$deadline = $_POST['deadline_text'];
$order = $_POST['order'];
$column = $_POST['column'];
TaskDB::createLog($order.' '.$column);
// convert the date
$pieces = explode('/', $deadline);
$month = $pieces[0];
$day = $pieces[1];
$year = $pieces[2];
$newDate = $year.'-'.$month.'-'.$day;
// create a new task object, add it to database
$task = new Task('DEFAULT', $description, $duration, $newDate, '0');
TaskDB::addTask($task);
TaskDB::generateTaskTable();
}
これがなぜなのか知っている人はいますか?