Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@masash49

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

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

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
4
Help us understand the problem. What are the problem?