简体   繁体   English

iframe传输不传输任何数据

[英]iframe transport isn't transferring any data

I'm using jQuery-File-Upload with jQuery-Iframe-Transport to try to get support for older versions of IE. 我正在使用jQuery-File-UploadjQuery-iframe-Transport来尝试获得对旧版IE的支持。

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. 我已经将forceIframeTransport选项设置为true以便它在所有浏览器中的行为大致相同,但是在使用iframe传输时,无论浏览器如何,我似乎都没有在服务器端获得任何数据。

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 indicated bleeped out info; [ *****表示泄露信息; you don't need that ;)] 你不需要那个;)]

Which look OK, but $_REQUEST is empty (ie, array() ), and the input buffer is empty too: 看起来没问题,但是$_REQUEST是空的(即array() ),输入缓冲区也是空的:

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

$file_data = '';

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

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

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? 当我不使用iframe传输但我需要IE支持时,这一切都运行正常...有没有人有使用iframe传输文件的经验,可能知道为什么没有数据通过?


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-File-Upload / js / jquery.iframe-transport.js并强制iframe传输时,它可以在Chrome中运行,但请求甚至不能在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. 当我使用jquery-iframe-transport / jquery.iframe-transport.js并强制iframe传输它在Chrome中断时,但这很好,因为Chrome支持正确的XHR文件传输, 并且请求至少在IE中命中服务器没有数据到来通过。

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]);
}

But again, I still can't seem to get any data in IE regardless of what I do. 但是,无论我做什么,我仍然无法在IE中获得任何数据。

When I say "IE", I'm specifically testing in IE 8 right now. 当我说“IE”时,我现在正专门在IE 8中进行测试。 I need support back to 7 though. 我需要支持回到7。 This guy claims support all the way back to IE 6. 这家伙声称支持一直回到IE 6。

After many hours, I've finally tracked down the issue. 几个小时后,我终于找到了问题。

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. 首先,你需要使用jQuery-file-upload捆绑的传输插件,因为它是为它制作的;)我不太确定为什么另一个更进一步,但我会在分钟。

I noticed in IE that I was getting an "access is denied" JavaScript error somewhere in the core jquery library. 我在IE中注意到我在核心jquery库中的某处获得了“访问被拒绝”的JavaScript错误。 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. 从我在网上看到的情况来看,这通常发生在你试图提交到不同域名的URL时,我没有这样做,所以我驳回了它。

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. 我正在比较两种不同的传输脚本的不同之处,当我在一个版本中使用form.submit()在另一个版本中使用form[0].submit()时。 So I tried adding the [0] and then noticed the "access has denied" error changed to point to that line. 所以我尝试添加[0] ,然后注意到“访问已拒绝”错误已更改为指向该行。 So clearly, it didn't like where I was submitting the files to. 很明显,它不喜欢我提交文件的地方。

I double checked the form.action and the URL still looked fine. 我仔细检查了form.action并且URL看起来仍然很好。 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. 通过一些Google-fu,我发现如果事件不是源自原始/本机文件输入元素,您也会收到此错误。

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. 这不喜欢。

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. 拿出我的假上传按钮并重新插入原生的按钮( <input type="file"/> fyi),现在一切都像所有浏览器中的魅力一样。 Huzzah! 好哇!

For what it's worth ... 物有所值 ...

I was working with jQuery v1.9.1 doing virus scanning on files synchronously before files are uploaded to the server. 我正在使用jQuery v1.9.1在文件上传到服务器之前同步对文件进行病毒扫描。 If the file had a virus, we WERE returning a HTTP 400, and HTTP 200 if not virus. 如果文件有病毒,我们会返回HTTP 400,如果不是病毒则返回HTTP 200。

The HTTP 400 response caused the IE8 "Access Denied" result. HTTP 400响应导致IE8“访问被拒绝”结果。

When I changed server reponse from 400 to 401, the UI worked perfectly. 当我将服务器响应从400更改为401时,UI完美运行。

Again, "For What It's Worth." 再次,“为了它的价值。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM