Skip to content Skip to sidebar Skip to footer

What Is The Alternative Of FormData In IOS?

I'm using xmlHTTPRequest (and also $.ajax) to send a form(that contain some text inputs and multi-file input) without refreshing the page. I'm using FormData to send the form succe

Solution 1:

I was able to use FormData with Safari on iOS 10.3.3 (iPhone 5C) like so:

var formData = new FormData(document.getElementById('form1'));
var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function(event) {
  if (xhr.readyState == 4) {
    if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
      // do something
    } else {
      // do something
    }

    // clean
    xhr = null;
  }
}

xhr.open('post', 'http://server/upload.php', true);
xhr.send(formData);
<form id="form1" action="upload.php" method="POST" enctype="multipart/form-data">
  <label id="bChoose" for="file">Choose</label>
  <input id="file" type="file" name="file" />
</form>

Post a Comment for "What Is The Alternative Of FormData In IOS?"