Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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は、本当にアレですね。

masash49
フロントエンドエンジニアとして働き出しました。 わからない事、調べた事、試した事を書いていきます。 https://github.com/masashi49 https://twitter.com/YMD22226133?s=09 主に調べること https://gyazo.com/7991302d40ea08944caae9c264665593
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした