Upload file with ajax ie8

Asked

Viewed 77 times

0

I have a Multipart-fordata form where I need to send the file for processing in C#.

The code below works on IE11 and Chrome.

var formData= new FormData();
var planilha = document.getElementById("planilha").files[0];

//formData.append("planilha", $("#planilha").file);
formData.append("planilha", planilha);
formData.append("codigoUsuario", $("#txt_ms_codusuario").val());

var xhr = new XMLHttpRequest();
xhr.open("POST", path_ROOT + "LimiteQuanti/EnviarArquivo", true);
xhr.addEventListener("load", function (evt) { UploadComplete(evt); }, false);
xhr.addEventListener("error", function (evt) { UploadFailed(evt); }, false);
xhr.send(formData);

But it doesn’t work for IE8.

Searching the web, I found an alternative to this, which is to use the jquery.form.js plugin

But when trying to execute the code below, I receive the message "Permission Denied".

var obj = { tipo: 'MULT_FORN', codigoUsuario: $("#txt_ms_codusuario").val() };

        $('#files').ajaxForm({
            data: obj,
            dataType: 'json',
            url: path_ROOT + "LimiteQuanti/EnviarArquivoBrowserAntigo",
            success: function (data) {
                NotificarAlerta('OS DADOS DO ARQUIVO FORAM CARREGADOS COM SUCESSO!');
            },
            error: function (jqXHR, textStatus, errorThrown) {
                NotificarErro('OCORREU UM ERRO AO GRAVAR O ARQUIVO.');
            },

            resetForm: true
        }).submit(); 

It won’t even call the action in the controller

[HttpPost]
public ContentResult EnviarArquivoBrowserAntigo(string tipo, string codigoUsuario)

Output of browser error: inserir a descrição da imagem aqui

My problem is in this snippet of code below. This input file is invisible and in its place appears a button and an input text, because it is stylized. While removing this code from my script and trying to select the file directly in the input file, it works. But if you run this code, the problem occurs

$(document).ready(function () {
    var versao = versaoIE();

    $('.btnSel').on('click', function () {
        $('.arquivo').trigger('click');
    });

    $('.arquivo').on('change', function () {
        var fileName = '';
        if ($(this)[0].files)
            fileName = $(this)[0].files[0].name;
        else
            fileName = $(this)[0].value;
        $('#file').val(fileName);
    });

});
  • Post console error message (F12) complete, "permission denied" is sure only part of the error, inform the line that triggered it, give details.

  • I don’t know why, but it seems to work only if the form contains only a single input field file: <form name="formUpload" id="formUpload" method="post"> <input type="file" Accept="image/*" id="fileUpload" name="fileUpload" /> </form>

  • Strange, can reproduce the code in something like jsfiddle?

  • I can’t make Fiddler work with IE, I need permissions to configure the local proxy in IE, if Fiddler doesn’t capture traffic for localhost. But I have no privileges to do so. There are network restrictions.

  • This input file is invisible and in its place appears a button and an input text, because it is stylized. While removing this code from my script and trying to select the file directly in the input file, it works. But if you run this code, the problem occurs.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.