項(xiàng)目需要,接口提交數(shù)據(jù)時(shí)會根據(jù)數(shù)據(jù)加密生成一個(gè)sing簽名,后端接口解密簽名之后會進(jìn)行比較缓待,然后發(fā)現(xiàn)iOS端的多行文本框換行時(shí)換行代碼\n在后端接收到是\r\n,但是提交數(shù)據(jù)的方式要是去掉new FormData()的話反而正常渠牲。找不到原因只能用點(diǎn)邪門歪道的方法旋炒,在代碼加密之前通過正則進(jìn)行轉(zhuǎn)換:
let ua = navigator.userAgent;
let isIOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
for (var key in newData) {
if (typeof newData[key] === "string" && isIOS) {
newData[key] = newData[key].replace(/[\n|\r\n]/g, "\r\n");
}
}