formData未定义

时间:2018-02-16 21:05:56

标签: javascript ajax

我有一个上传文件的回调。很标准:

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()

0 个答案:

没有答案