製品テーブルを含むフォームがあります。最初はテーブルは空で、ボタンを押すだけで新しい製品が動的に挿入されます。ユーザーが送信ボタンを押すと、「preview.php」ページにリダイレクトします。しかし、最初に関数でカスタム JSON オブジェクトを作成し、このオブジェクトで POST リクエストを作成してから、「preview.php」にリダイレクトする必要があります。それは可能ですか?そして、これを実行するためのより良い方法は何ですか?
これが私のファイルのサンプルです:
//------------
//invoice.php
//------------
<form id="newInvoice" action="preview.php">
<table>...</table>
<button type="submit">Preview</button>
</form>
//-----------
//invoice.js
//-----------
$('#newInvoice').submit(function() {
var data = [
"invoicenumber": code,
"client": {"firstname":"", "lastname":"", ...},
"products": [{...}, {...}, {...}], //multiple products
//building the rest of my data here
];
// I don't know what to do here.
// A call to $.post would send my data asynchronously but I want
// to send the data as I would do from invoice.php and be redirected
// to preview.php.
});
//------------
//preview.php
//------------
$data = json_decode($_POST['data']); // is this correct ?
//...
ご回答ありがとうございます。