Iframe transport does not transmit data

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

I set the forceIframeTransport parameter to true so that it works more or less the same in all browsers, but I do not seem to return data on the server side regardless of the browser when it uses the iframe transport.

I spat out the server request headers and I returned:

 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 => "*********" ) 

[ ***** error information indicated; you do not need it;)]

Which view is OK, but $_REQUEST 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 = ''; 

All this worked fine when I did not use iframe transport, but I need IE support ... does anyone have experience transferring files using iframes and can know why the data is not arriving?


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

When I use jquery-iframe-transport / jquery.iframe-transport.js and forcibly transfer the iframe to Chrome, but this is fine because Chrome supports the correct XHR file transfers and the requests at least get to the server in IE, but the data do not arrive.

I updated my script to support the 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 then again, I still cannot get any data in IE, no matter what I do.

When I say "IE", I am specifically testing in IE 8 right now. I need support even before 7. This guy claims support completely in IE 6.

+4
source share
2 answers

After many hours, I finally tracked the problem.

Firstly, you need to use the transport plugin that comes bundled with downloading the jQuery file because it was made for it;) I'm not quite sure why the other took a step further, but I will get there in a minute.

I noticed in IE that I was getting the "access denied" JavaScript error somewhere in the main jquery library. From what I read on the Internet, this usually happens when you try to send a URL in a different domain, which I did not do, so I rejected it.

I compared what two different transport scenarios did when I came to a line that said form.submit() in one version and form[0].submit() in another. So I tried to add [0] , and then noticed that the "access denied" error had changed to point to this line. It’s so clear that I didn’t like where I send the files.

I double-checked form.action and the url still looked great. Through some google-fu, I found that you can also get this error if the event does not come from the source / source file input element.

I replaced the native input with a fantastic one, and then raised the 'fake' click event on a hidden private input. He didn’t like it.

He pulled out my fake download button and hung up the native one again ( <input type="file"/> fyi), and now everything works like a charm in all browsers. Hooray!

+10
source

What is it worth ...

I worked with jQuery v1.9.1, performing an antivirus scan of files before the files are uploaded to the server. If the file had a virus, we returned HTTP 400 and HTTP 200, if not a virus.

An HTTP 400 response triggered an IE8 Access Denied result.

When I changed the server response from 400 to 401, the user interface worked fine.

Again, "Why is it worth it."

0
source

All Articles