我正在將數據傳遞到我的php腳本使用jQuery的.ajax
方法。我將一個非常複雜的JSON對象作爲數據傳遞。在服務器端,我收到的數據都在$_POST
變量中全部轉換爲php格式。如何將數據從JSON轉換爲php格式
這種轉換是如何發生的?它發生在客戶端還是服務器端?在這個過程中關聯哪些模塊。任何來源深入瞭解完整的過程。
客戶端請求:
var data = {
foo: 123,
bar: 456,
rows: [
{
column1 : 'hello',
column2 : 'hola',
column3 : 'bonjour',
},
{
column1 : 'goodbye',
column2 : 'hasta luego',
column3 : 'au revoir',
},
],
test1:{
test2: {
test3: 'baz'
}
}
};
$.ajax({
type: 'post',
cache: false,
url: './ajax/',
data: data
});
在服務器端我的 '$ _ POST' VAR:
Array
(
[foo] => 123
[bar] => 456
[rows] => Array
(
[0] => Array
(
[column1] => hello
[column2] => hola
[column3] => bonjour
)
[1] => Array
(
[column1] => goodbye
[column2] => hasta luego
[column3] => au revoir
)
)
[test1] => Array
(
[test2] => Array
(
[test3] => baz
)
)
)
這段代碼是從here拍攝。
如何指定嵌套數據?我嘗試閱讀'multipart/form-data',但無法理解它是如何完成的。 此外,轉換必須發生在PHP從HTTP格式到PHP格式。 – 2013-03-23 21:25:41
是的,這是正確的。然後,PHP將HTTP格式轉換爲其數組格式 - GET,POST或REQUEST。 – 2013-03-23 21:33:53
嵌套數據的任何幫助? – 2013-03-23 21:45:41