I am trying to upload a picture using jquery. and the upload should be done with no page refresh.
the code:
var uploader = new qq.FileUploaderBasic({
element: document.getElementById('file-uploader'),
button: $('#account #picture .header')[0],
action: '<?= Route::url('Account Upload Avatar'); ?>',
allowedExtensions: ['png', 'jpg', 'gif'],
onSubmit: function()
{
},
onComplete: function(id, fileName, avatar)
{
$('#loader').hide();
$('#picture img').attr('src', responseJSON + '?' + (new Date).getTime());
}
});
and where i have the picture upload:
<div id="picture">
<div class="header">
Schimba-ti poza
</div>
<img src="<?= $image->avatar_url ?>"></img>
</div>
the problem is:
the upload is done right, but i can see the new picture only if i refresh the page. otherwise, when i upload a new picture, the old one dissapears, and instead appears an image broken icon, and if i inspect the element, i see: <img id="picture" src="undefined?1308840720252">
so i get that undefined.. and i guess it is because that attr.
i am using jquery 1.6.1
any ideas?
thank you!