I can’t get this script working. Every time I send a file the script need to do one ajax request and send to server the file, but, serialize always send empty string.
My Javascript
$('#upload-button input:file').change(function() {
$('#upload-text').text('Sending file...');
$.ajax({
type: "GET",
url: "?url=images/send",
data: $('#image-upload').serialize(),
success: function(response) {
if(response.error) {
$('#upload-text').text(response.error);
} else if(response.success) {
$('#upload-text').text('Image send');
}
},
});
})
My HTML
<form name="image-upload" id="image-upload" action="?url=imagens/enviar" method="post" enctype="multipart/form-data">
<input type="file" name="selected-image" id="upload-hidden" value="" />
</form>
When I have selected a file, result from alert($('#image-upload').serialize());:
// EMPTY //
Result from alert($('#image-upload input:file').attr('value')):
ponte-vecchio.jpg
Use the jQuery form plugin. It supports HTML5 file uploads and can fallback to a hidden iframe if the browser is too old.