iframe传输未传输任何数据 [英] iframe transport isn't transferring any data

查看:146
本文介绍了iframe传输未传输任何数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 jQuery-File-Up

I'm using jQuery-File-Upload with jQuery-Iframe-Transport to try to get support for older versions of IE.

我已将 forceIframeTransport 选项设置为,以便它在所有浏览器中的行为大致相同,但是无论使用iframe传输的浏览器如何,我似乎都无法在服务器端获取任何数据.

I've set the forceIframeTransport option to true so that it behaves more or less the same way in all browsers, but I don't seem to get any data back on the server-side regardless of browser when it uses the iframe transport.

我已经在服务器端吐出了请求标头,然后返回了:

I've spat out the request headers server-side and I get back:

array(
    Host => "*******"
    Connection => "keep-alive"
    Content-Length => "0"
    Accept => "*/*"
    Origin => "**************"
    X-Requested-With => "XMLHttpRequest"
    User-Agent => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"
    DNT => "1"
    Referer => "***********"
    Accept-Encoding => "gzip,deflate,sdch"
    Accept-Language => "en-GB,en-US;q=0.8,en;q=0.6"
    Accept-Charset => "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
    Cookie => "*********"
)

[***** s表明信息泄漏;您不需要那;)]

[*****s indicated bleeped out info; you don't need that ;)]

看起来不错,但$_REQUEST为空(即array()),并且输入缓冲区也为空:

Which look OK, but $_REQUEST is empty (i.e., array()), and the input buffer is empty too:

$handle = fopen('php://input', 'r');

$file_data = '';

while(($buffer = fgets($handle, 4096)) !== false) {
    $file_data .= $buffer;
}

fclose($handle); // $file_data = '';

当我不使用iframe-transport但我需要IE支持时,所有这些都工作正常……是否有人有使用iframe传输文件的经验,并且可能知道为什么没有数据通过?

This all worked fine when I wasn't using the iframe-transport but I need IE support... does anyone have any experience with transmitting files using iframes and might know why no data is coming through?

当我使用 jQuery文件时-Upload/js/jquery.iframe-transport.js 并强制iframe传输可在Chrome中运行,但请求甚至无法到达IE中的服务器.

When I use jQuery-File-Upload / js / jquery.iframe-transport.js and force iframe transport it works in Chrome, but the requests don't even make it to the server in IE.

当我使用 jquery-iframe-transport /jquery.iframe-transport.js 并强制iframe传输在Chrome中中断,但这很好,因为Chrome支持正确的XHR文件传输,的请求至少会在IE中到达服务器但是没有数据通过.

When I use jquery-iframe-transport / jquery.iframe-transport.js and force iframe transport it breaks in Chrome, but that's fine because Chrome supports proper XHR file transfers, and the requests at least hit the server in IE but no data comes through.

我已经更新了我的脚本以支持任何一种传输方法:

I've updated my script to support either transfer method:

if(empty($_FILES)) {
    $handle = fopen('php://input', 'r');

    $file_data = '';

    while(($buffer = fgets($handle, 4096)) !== false) {
        $file_data .= $buffer;
    }

    fclose($handle);
} else {
    $file_data = file_get_contents($_FILES['files']['tmp_name'][0]);
}

但是,无论如何,我仍然似乎无法在IE中获取任何数据.

But again, I still can't seem to get any data in IE regardless of what I do.

当我说"IE"时,我正在专门在IE 8中进行测试.我需要回到7的支持. 这个家伙声称从IE 6开始就一直支持.

When I say "IE", I'm specifically testing in IE 8 right now. I need support back to 7 though. This guy claims support all the way back to IE 6.

推荐答案

许多小时后,我终于找到了问题所在.

After many hours, I've finally tracked down the issue.

首先,您需要使用附带的传输插件与jQuery-file-upload捆绑在一起,因为它是专门为它而准备的;)我不太确定为什么另一个人会更进一步,但是我会在一分钟内解决这个问题.

First, you need to use the transport plugin that comes bundled with jQuery-file-upload because it was made for it ;) I'm not quite sure why the other one got a step further, but I'll get to that in a minute.

我在IE中注意到,我在核心jquery库中某处遇到了访问被拒绝" JavaScript错误.根据我在网上阅读的内容,通常会在您尝试提交到其他域的URL时发生这种情况,而我没有这样做,因此我将其驳回了.

I noticed in IE that I was getting an "access is denied" JavaScript error somewhere in the core jquery library. From what I read online this usually happens when you try to submit to a URL at a different domain, which I wasn't doing, so I dismissed it.

我比较的是两种不同的传输脚本的不同之处,当我到达的一行在一个版本中表示form.submit(),在另一个版本中表示form[0].submit().因此,我尝试添加[0],然后注意到访问已拒绝"错误已更改为指向该行.显然,它不喜欢我将文件提交到的位置.

I was comparing what the 2 different transport scripts did differently, when I came to a line that said form.submit() in one version, and form[0].submit() in the other. So I tried adding the [0] and then noticed the "access has denied" error changed to point to that line. So clearly, it didn't like where I was submitting the files to.

我再次检查了form.action,URL仍然看起来不错.通过一些 Google-fu ,我发现如果事件不是由您引起的,您也会遇到此错误来自原始/本地文件输入元素.

I double checked the form.action and the URL still looked fine. Through some Google-fu I discovered that you can also get this error if the event does not originate from the original/native file input element.

我用一个花哨的输入替换了本机输入,然后在隐藏的本机输入上触发了一个假"点击"事件.这不喜欢.

I had replaced the native input with a fancy one and then triggered a "fake" 'click' event on the hidden native input. This it didn't like.

拿出我的假上载按钮,然后放回原生按钮(<input type="file"/> fyi),现在所有功能在所有浏览器中都像个魅力.众议院!

Took out my fake upload button and plopped the native one (<input type="file"/> fyi) back in, and now everything works like a charm in all browsers. Huzzah!

这篇关于iframe传输未传输任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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