我正在尝试发布此表单:
<form id="the-form" enctype="multipart/form-data" >
<textarea class="form-control" name="list" id="list"></textarea>
</form>
使用此脚本:
$.post( "/route", $('#the-form').serialize());
脚本的调试显示 JSON.stringify($('#list').val())
返回“line1\nline2\nline3”
而 $('#the-form').serialize()
返回
wordlist=line1%0D%0Aline2%0D%0Aline3
。
那么为什么jquery.serialize将\n
编码为%0D%0A
?有没有办法让 serialize 返回带有 %0A
EOL 的字符串?
最佳答案
这是设计使然,请参阅 here :
When serializing text, encode all line breaks as CRLF pairs per the application/x-www-form-urlencoded specification.
其中says :
Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
--
Is there a way to make serialize return string with %0A EOL?
除了在序列化后手动删除 %0D
之外,没有其他操作。
关于javascript - 为什么 jquery.serialize 将 LF 更改为 CRLF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31987019/