0

I have a problem and i need some help. I just want to upload a file in Ajax with an input type file. And then without reload the page, show this pdf under my form on an iframe. I started like that :

$('#myform').on('submit.pdf-add', function(e){
    e.preventDefault();
    var $form = $(this);
    var url= $form.attr('action');
    $.ajax({
        type: "POST",
        url: url,
        data: {},
        dataType: 'json'
    })
    .done(function(data){
        if ($('input[type=file]').val().length != 0) {
            data_parsed = data;
            $('<p class="success">Le pdf a été uploadé avec succès !</p>').append($form);
            $form.append('<iframe src="'+ data_parsed +'" width="100%" height="95%"></iframe>');
            $form.off('submit.pdf-add');
        } else {
            $('<p class="fail">Le pdf est inexistant !</p>').append($form);
        }
    })
    .fail(function(data){
        console.log(data);
        $("<p class='fail'>Le fichier n'a pas été uploadé</p>").append($form);
    });
});*

I know File API is better but i need a cross browser support ! Thanks !

Adrian Forsius
  • 1,437
  • 2
  • 19
  • 29

0 Answers0