這是前台ajax方法
#這是傳輸前的files內容
這是提交之後的後台req.body接受到的內容
#請問為啥會自動遍歷輸出了files呢 ?我別的什麼也沒幹呀,只想將files作為整體返回給後台
我想大声告诉你2017-06-17 09:18:00
資料傳輸的時候是以key/value的形式拼接的,value的值必須是string,如果是複雜物件({}/[]),會遍歷後拆成最小的單元以滿足key/value鍵值對。建議你將files值轉換為string(JSON.stringify(files)),後台收到資料後再轉換回來(JSON.parse())。
$.ajax({
url:'xxx',
type: 'post',
dataType: 'json',
data: {
title: title,
belongTo: belongTo,
content: content,
files: JSON.stringify(files)
}
})