Change background of a DIV in iframe

0

Next Person,

I have a form to upload any image ...

<form id="form-upload" enctype="multipart/form-data" action="url" method="post">
    <input type="file" name="image" id="image" />
    <input type="submit" name="salvar" value="Salvar" />
<form>

I want to put the image that was sent as background of a div in an iframe, using ajax, so I do not need to refresh the page, I would like to know a way to do this, is it really necessary to upload the image? >

My JS code:

$('#form-upload').on('submit',function (e) {
    e.preventDefault();

    var formData = new FormData(this);

    $.ajax(
    {
        url: uma_url_qualquer,
        type: 'POST',
        data: formData,
        success: function (data) {
            console.log("sucesso");
        },
        cache: false,
        contentType: false,
        processData: false
    });
});
    
asked by anonymous 27.04.2015 / 00:09

1 answer

2

Yes it is possible, and if the image should not be saved to be displayed every time the user accesses the page, you do not even need to upload ...

$('#arquivo').change(function(e) {
    var _arq = URL.createObjectURL(e.target.files[0]);
    $("#frame").contents().find("#div").css('background-image','url('+_arq+')');
});

See the example working here: link

    
27.04.2015 / 14:01