[英]iframe upload browser compatibility
I'm uploading a csv file using the iframe approach. 我正在使用iframe方法上传一个csv文件。 I was hoping that it would allow me to not have the redirect of the page on a normal form submittal.
我希望这将使我不必在常规表单提交上进行页面重定向。
HTML: HTML:
<section id=fileImport>
<form id="importForm" target="postiframe" name="Import" enctype="multipart/form-data">
<input name="import-input" id="importInput" type="file" />
<button id="importBtn" class="btn btn-large">Import</button>
</form>
</section>
javascript: JavaScript的:
var iframe = $('<iframe name="postiframe" id="postiframe" style="display: none" />');
this.$("#fileImport").append(iframe);
var form = $("#importForm");
form.attr("action", "import/upload");
form.attr("method", "post");
form.attr("enctype", "multipart/form-data");
form.attr("encoding", "multipart/form-data");
form.attr("target", "postiframe");
form.submit();
var self = this;
this.$("#postiframe").load(function () {
var iframeContents = $("#postiframe").get(0).contentWindow.document.body.innerHTML;
self.parseResponse(iframeContents);
});
enter code here
This is my first attempt at using this iFrame approach. 这是我首次尝试使用这种iFrame方法。 I thought in parseResponse I could just take the data that comes back in the pre tags.
我认为在parseResponse中,我可以只获取pre标签中返回的数据。
eg 例如
<pre>{myData: "blah"}</pre>
I was doing that with: 我这样做是:
var re = new RegExp("<pre>(.*?)</pre>");
var matches = response.match(re);
And that worked for Firefox. 这对Firefox很有用。 Then when I tried it in chrome, chrome sends the data back with stuff like
然后,当我在chrome中尝试使用chrome时,它将诸如
<pre style="width:....">{myData: "blah"}</pre>
I was wondering if there was a way to get the data back without the pre tags, or a way to possibly parse it amongst the different browsers. 我想知道是否有一种方法可以在没有前置标签的情况下取回数据,或者有可能在不同的浏览器之间解析数据。 I haven't tried it on IE 9, but I can only imagine it being harder than chrome & firefox.
我没有在IE 9上尝试过,但是我只能想象它比chrome和firefox难。 Any thoughts?
有什么想法吗?
Is using an iframe like this to upload data still used? 是否仍在使用像这样的iframe上传数据? (We have to support IE 9, so I can't use the html 5 stuff).
(我们必须支持IE 9,所以我不能使用html 5东西)。
Cross domain upload? 跨域上传?
If so, you need a redirect page to receive result from query string. 如果是这样,您需要一个重定向页面来接收来自查询字符串的结果。
If not, do not use iframe upload, http://jquery.malsup.com/form/ , here is a plugin help to post form async. 如果没有,请不要使用iframe上传http://jquery.malsup.com/form/ ,这是发布表单异步的插件帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.