私は今これに約2〜3時間取り組んでいますが、どこが間違っているのかわかりません。これは、オブジェクトを作成する私の jQuery です。
var data = {cat:[],count:[],size:[],type:[],print:[]};
$("#Cat-list option").each(function()
{data.cat.push($(this).val());});
$("#Count-list option").each(function()
{data.count.push($(this).val());});
$("#Size-list option").each(function()
{data.size.push($(this).val());});
$("#Print-list option").each(function()
{data.print.push($(this).val());});
$("#Type-list option").each(function()
{data.type.push($(this).val());});
この後、データという名前のオブジェクトができます。obj を JSON に変換すると、次のvar jsonString=JSON.stringify(data);
ようになります。
{
"cat":["Cart Visit","Bag","Envelope","Tracket","Brosur"],
"count":["1000","2000","4000","5000","?????"],
"size":["S","M","L","X"],
"type":["?? ??","??? ? ??","????"],
"print":["????","???????","????"]
}
次に、jQuery Ajax を使用して、次のように jsonstring を php ファイルに送信します。
$.ajax({
type: "POST",
url: 'update_db.php',
data: jsonString,
contentType: "application/json; charset=utf-8",
success:
function(result) {
$( "#alert").html( result );
}
});
最後に、phpスクリプトでデータを受信しようとしています。このデータを取得する方法がわかりません。「jsonstring」と「data」で試しました。
$json = json_decode( $_POST['jsonstring']);
$data = json_decode( $_POST['data']);
var_dump($json);
var_dump($data);
しかし、どちらも「NULL」です。私は何を間違っていますか?