IOS中FormData的替代方法是什么? [英] what is the alternative of FormData in IOS?

查看:222
本文介绍了IOS中FormData的替代方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xmlHTTPRequest(以及$ .ajax)发送表单(包含一些文本输入和多文件输入)而没有刷新页面.我正在使用FormData在PC(Chrome)上成功发送表单.当我在IPAD(IOS)中运行该页面时,该页面无法正常工作.在尝试知道错误在哪里之后,似乎其中不支持FormData.就我而言,还有其他选择吗?

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 successfully on PC (Chrome). When I run the page in my IPAD (IOS), it didn't work. After trying to know where the error was, it seemed that FormData not supported in it. Is there any alternative for it in my case ?

var formDataH = new FormData($('#FeedbackForm')[0]);
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (this.readyState == 4) {
        if (this.status == 200){
            alert(xhttp.responseText);
        $('#FeedbackBar').html('<span class="text-success">Sent...</span>');
        $('#FeedbackForm')[0].reset();
        }else{
            $('#FeedbackBar').html('<span class="text-danger">Error Sending, try again...</span>');
        }
        setTimeout(function() {$('#FeedbackBar').html('');}, 2000);
      }
    };

    xhttp.open("POST", "conf/feedbackpost.php", true);    
    xhttp.send(formDataH);

推荐答案

我能够在iOS 10.3.3(iPhone 5C)上的Safari上使用FormData,如下所示:

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>

这篇关于IOS中FormData的替代方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆