Ajax forms don't work in IE #136

Closed
robinharms opened this Issue Dec 11, 2012 · 3 comments

Comments

Projects
None yet
4 participants
Contributor

robinharms commented Dec 11, 2012

  • the XHR header isn't set so Pyramid and other frameworks can't identify it as an AJAX call. (It works on other browsers of course :)
  • The demo on http://deformdemo.repoze.org/ajaxform won't accept any submitted data when using IE9

I have the same issue, using 0.9.6 at the moment.

It looks like this issue is in jquery.form-3.09.js, lines 175-202:

var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
var hasFileInputs = fileInputs.length > 0;
var mp = 'multipart/form-data';
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);

var fileAPI = feature.fileapi && feature.formdata;
log("fileAPI :" + fileAPI);
var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
// options.iframe allows user to force iframe mode
// 06-NOV-09: now defaulting to iframe mode if file input is detected
if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
    // hack to fix Safari hang (thanks to Tim Molendijk for this)
    // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
    if (options.closeKeepAlive) {
        $.get(options.closeKeepAlive, function() {
            fileUploadIframe(a);
        });
    }
      else {
        fileUploadIframe(a);
      }
}
else if ((hasFileInputs || multipart) && fileAPI) {
    fileUploadXhr(a);
}
else {
    $.ajax(options);
}

This line in particular:

var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;

fileAPI is false for IE <= 9, and multipart is always true as far as I can tell.

Then there's this test:

if (options.iframe !== false && (options.iframe || shouldUseFrame)) {

options.iframe is undefined, so this test passes and it tries to initiate an iframed file upload.

Changing

var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;

to

var shouldUseFrame = hasFileInputs && multipart && !fileAPI;

let's me use ajax forms in IE9, but I don't know if it affects file uploads as I don't use them.

yazaki commented Jul 31, 2013

I have the same issue.

The issue is in jquery.form-3.09.js (line 177-).

var mp = 'multipart/form-data';
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);

var fileAPI = feature.fileapi && feature.formdata;
var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;

When the browser doesn't have fileAPI like IE7-9 and html form have 'enctype="multipart/form-data"',
jquery.form decide to use iframe.

On the other hand,
deform always output 'enctype="multipart/form-data"' even if we don't need to upload file,
(I think this way of deform should be improved.)

So all ajax form with deform cause this issue when the browser is IE(7-9).

My solution is as follows.

jquery.form have the option for stopping to use iframe.
We can see it in jquery.form-3.09.js (line 186).

if (options.iframe !== false && (options.iframe || shouldUseFrame)) {

So if we don't need to upload file in our ajax form, we can set the iframe options false.
When we do this with deform, we can use parameter 'ajax_options' of deform.Form constructor.

As follows.

form = Form(myschema, use_ajax=True, ajax_options='{iframe: false}')

Of course we need other solution, if we need to upload file in ajax form.

Contributor

miohtama commented Dec 6, 2016

Solved by Microsoft killing IE.

miohtama closed this Dec 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment