-
傳遞格式
- 在ajax中的參數(shù)傳遞格式如下
data: {
Member: that.formMember,
'_csrf-backend': "<?= Yii::$app->getRequest()->getCsrfToken();?>",
cacheKey: "<?= $cacheKey?>"
},
其中 that.formMember為一個(gè)對(duì)象
可以看出:嵌套的對(duì)象會(huì)轉(zhuǎn)換成了數(shù)組的格式,索引數(shù)組的形式也可以存在
一個(gè)鍵如果沒(méi)有對(duì)應(yīng)值,則沒(méi)有數(shù)據(jù)被傳遞
在前端頁(yè)面中采用的數(shù)字類(lèi)型將被轉(zhuǎn)化成string,bool類(lèi)型被轉(zhuǎn)換成string
演示如下:
test:1,
test1:'1',
test2:'',
test3:null,
test4:true,
Member[test]:1
Member[test1]:1
Member[test2]:
Member[test3]:
Member[test4]:true
formData中的數(shù)據(jù)如下:
Member[m_photo]:
Member[m_name]:王會(huì)南
Member[m_gender]:woman
Member[m_birthday]:19930428
Member[m_nation]:漢族
Member[m_native][]:130000
Member[m_native][]:130400
Member[m_native][]:130406
Member[m_join_date]:20180120
Member[m_id_card]:黨員35
現(xiàn)在來(lái)看后臺(tái)接收的格式:
可以看出Member為數(shù)組,Member中的m_photo接收到了空字符串,m_native為索引數(shù)組
后臺(tái)接收數(shù)據(jù)如下:
<b>array</b> <i>(size=3)</i>
'Member' <font color='#888a85'>=></font>
<b>array</b> <i>(size=25)</i>
'm_photo' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>''</font> <i>(length=0)</i>
'm_name' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'王會(huì)南'</font> <i>(length=9)</i>
'm_gender' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'woman'</font> <i>(length=5)</i>
'm_birthday' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'19930428'</font> <i>(length=8)</i>
'm_nation' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'漢族'</font> <i>(length=6)</i>
'm_native' <font color='#888a85'>=></font>
<b>array</b> <i>(size=3)</i>
0 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'130000'</font> <i>(length=6)</i>
1 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'130400'</font> <i>(length=6)</i>
2 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'130406'</font> <i>(length=6)</i>
-
總結(jié)
- 只要出現(xiàn)在對(duì)象中鍵都將會(huì)被傳遞,沒(méi)有值將會(huì)被作為空字符串傳遞
- 在頁(yè)面往服務(wù)器的傳參過(guò)程中,數(shù)字與bool類(lèi)型都將被作為字符串傳遞
- 嵌套的對(duì)象將會(huì)被作為數(shù)組形式傳遞