我有一个上传文件的回调。很标准:
function sendFile(file) {
formData = new FormData()
formData.append('photo[uploaded_image]', file)
$.ajax({
data: formData,
type: 'POST',
url: '/photos',
contentType: false,
processData: false,
success: function(response) {
console.log(`uploaded ${response.photo}`)
},
error: function(response) {
console.log(`couldn't upload: ${response}.`)
}
})
为什么我收到此错误
未捕获的ReferenceError:未定义formData
在函数的第2行?
formData = new FormData()