在formdata中追加对象显示为空。Formdata对象即使在调用append后也显示为空
<!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…}
为什么追加为FORMDATA不工作?
这也不能正常工作。我仍然得到Formdata {} –
@KanikaMidha让我知道你是否还有问题。 :) –