【发布时间】:2019-07-30 02:36:46
【问题描述】:
在formdata中追加对象显示为空。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var formy = new FormData();
formy.append("file", $("#file")[0].files[0]);
console.log(formy);
});
});
</script>
</head>
<body>
<input id="file" type="file" size="40"><br><br>
<button>Send an HTTP POST request to a page and get the result back</button>
</body>
</html>
上面代码在控制台日志中的输出给了我
Formdata{}
append:function append()
arguments:null
caller:null
length:2
name:"append"
而console.log($("#file")[0].files[0]) 给了我文件{name: "document.pdf", lastModified: 1462959300000, lastModifiedDate: Wed May 11 2016 15:05:00 GMT+0530 (IST), webkitRelativePath: "", size: 5275…}
为什么附加表单数据不起作用?
【问题讨论】:
标签: javascript jquery html