PHP から配列を取得し、jQuery を使用してさらに操作しようとしています。私のPHPファイルecho json_encode($data)
では、jQueryの応答にアラートを入れると、次のようになります。
[
{
"CustomerID": "C43242421",
"UserID": "432421421",
"Customer": "rqewrqwreeqwr",
"Add1": "rqwerqwreqwrqwrqwr",
"Add2": " ",
"Add3": " ",
"Phone": "4131231",
"Fax": "532442141",
"Contact": "reqwrqwrw",
"Email": "gfdgdsg",
"PaymentTerm": null,
"Country": "3231",
"City": "111",
"Zip": " "
}
]
、これは有効な json 配列です。今、私がさらにやろうとしているのは、php の連想配列で行うように、キー => 値としてペアを取得することです。
$.post("templates/test.php",
{data: query,
cond: $(this).text(),
action: 'select'
},
function(res) {
alert(res) //outputs what i pasted above
$.each($.parseJSON(res), function(key, value) {
alert(key + value);
//this outputs: 0[object Object]
});
$.parseJSON
上記の関数の を削除するとinvalid 'in' operand e on jquery.min.js(line 3)
、Firebug のエラー ログが表示されます。