Upload file with ajax ie8

0

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

The code below works in 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 does not work for IE8.

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

But when I try to run the code below, I get 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(); 

Do not even call the action on the controller

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

Error output in browser:

My problem is in this code snippet below. This input file is invisible and in its place a button and an input text appear because it is stylized. When removing this code from my script and trying to select the direct file 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);
    });

});
    
asked by anonymous 11.09.2017 / 22:51

0 answers