我有以下代码。问题是:表单数据对象data
始终为空。它在服务器端也是空的。我的代码中有错误吗?
<!DOCTYPE html>
<body>
<script src="jquery.min.js"></script>
<form enctype="multipart/form-data" method="post" name="insert" id="insert">
<input type="text" name="headline" id="headline" placeholder="headline" value="hl"/><br/>
<!--input type="file" name="image" id="image"/><br/-->
<textarea name="text" placeholder="Text">my text</textarea><br/>
<input type="submit" name="submit"/>
</form>
<script>
$("#insert").submit(function (e) {
e.preventDefault();
var data = new FormData(this);
console.log(data);
$.ajax({
url: '/api/blog/entry',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'post',
success: function (data) {
console.log(data);
},
error: function (error) {
console.log(error);
}
});
e.preventDefault();
});
</script>
</body>
</html>