AJAX request fails when sending FormData() including empty file input in Safari 10.13.4

前端 未结 5 1200
一生所求
一生所求 2020-12-14 10:48

I am running a Symfony 2.8 based web app which sends some form data back to a controller using Ajax.

So far everything worked fine, but since the latest macOS update

5条回答
  •  独厮守ぢ
    2020-12-14 11:11

    Meanwhile I found this quick and dirty solution. But actually I am looking for a real workaround. Any ideas?

    // Filter out empty file just before the Ajax request
    // Use try/catch since Safari < 10.13.4 does not support FormData.entries()
    try {
       for (var pair of data.entries()) {
          if (pair[1] instanceof File && pair[1].name == '' && pair[1].size == 0)
             data.delete(pair[0]);  
       }
    } catch(e) {}
    

提交回复
热议问题