5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IOS11.3でformDataを使って画像とテキストを同時に送ろうとしたら「キャンセル」されてしまう

Last updated at Posted at 2018-04-04

jqueryのajaxを使用して、formDataを使っており、画像とテキストを同時に送る場合、なぜかキャンセルされてしまう現象が起こった。

さっそく解決策

      var ua = navigator.userAgent
      var formData_ = new FormData($('#form').get(0));

      if(/iPhone/.test(ua)) {
        ua.userAgent.match(/iPhone OS (\w+){1,3}/g);
        var iosv=(RegExp.$1.replace(/_/g, '')+'00').slice(0,3);
        if(iosv === '113') {
          if(!$("#image").val()) {
            formData_.delete('image'); //name属性をdelete
          }
          if(!$("#content").val()) {
            formData_.delete('content');//name属性をdelete
          }
        }
      }


fileがない場合、fileを消す
textがない場合、textを消す
両方ある場合、何もしない

IOSとiEは、本当にアレですね。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?