我正在使用以下代码创建一个提供从ajax调用获取的数据的文件。
$.ajax({
url: xxx,
type: "POST",
data: path,
contentType: "text/plain; charset=utf-8",
async: false,
success: function (data, textStatus, xhr) {
if (xhr.status == 200) {
var file = new File({
name: 'abc.xyz',
path: 'path/to',
content: data.content
});
} else {
}
}
此操作因以下浏览器控制台错误而失败
Uncaught TypeError: Failed to construct 'File': 2 arguments required, but only 1 present.
at Object.success (BaseTest.js:44)
at n (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at w (jquery.min.js:4)
at d (jquery.min.js:4)
at Object.send (jquery.min.js:4)
at Function.ajax (jquery.min.js:4)
at myFunction (BaseTest.js:32)
at BaseTest.js:21
at Function.req.execCb (require.js:1660)
这个问题的原因是什么?
注意:var f = new File([""], "filename.txt", {type: "text/plain", lastModified: date})
工作正常但我的方法错误是什么