[eluser]Sven Delle[/eluser]
I'm trying to post a form with a file upload via jquery ajax. Simple, right?
Absolutely not. I've read hundreds of posts, downloaded all kinds of solutions. Watched video tutorials, and even created a simple CI project with only one controller and one view to make this work. And it did ... until I mixed in jQuery AJAX. What a nightmare.
I'm simply trying to post a form like this:
Code:
[removed]
$(function(){
$('#upload_media').submit(function(event) {
event.preventDefault();
if($('#userfile').val() === '')
{
alert('Please, select a file to upload ...');
return false;
}
// var form_data = $('#upload_media').serialize();
var form_data = { 'userfile' : $('#userfile').val(), 'upload' : $('#submit').val() };
alert(form_data.upload);
$.ajax({
url: '<?php echo base_url(); ?>upload/upload_media',
type: "POST",
data: form_data,
success: function(msg)
{
alert('Success: ' + msg);
}
});
// prevents from refreshing the page
return false;
});
});
[removed]
I can trace back a success, but my files NEVER gets uploaded to the server ... in this case localhost.
I have taken the code from the documentation and made a small project containing only that - without jquery. I've ported to code to my project, but no matter what I try the files never reach the server.
Can anyone tell me what I'm missing. Spent the whole god damn day on this. It's 14 F O U R T E E N hours!!!!