【发布时间】:2021-08-22 19:46:57
【问题描述】:
$('#submit2').click(e => {
e.preventDefault();
var form_data = new FormData();
form_data.append('newKey1', 'newValue1');
form_data.append('newKey2', 'newValue2');
console.log("data after appended", form_data.get('newKey1'))
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="submit2">See form data in Console</button>
我想在表单数据中添加文件,但我无法追加,所以我尝试添加键和值,但无法在表单数据中追加。
【问题讨论】:
-
它似乎工作正常。日志消息是“附加 newValue1 后的数据”
-
我已经更新了您的代码 sn-p,因此您可以看到您的
FormData设置了值。你不能console.log你的FormData实例并期望打印整个对象。
标签: javascript jquery forms form-data