• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I seriously need help uploading files in CI using jQuery AJAX!

[eluser]Sven Delle[/eluser]
I have a two div setup, where I have my main navigation on the left and all content on the right. I update the right div using jQuery AJAX calls to retrieve views of all kinds.

But I'm in a culprit when it comes to uploading files with jQuery AJAX, as it tends to use the post (or ajax) function which then receives some data back on success.

This is what I usually use to get data into my admin_view:

$('#admin_content').html('Getting data ...');
var data = {};
$('#admin_content').load(url, data, function(str) {

But a typical ajax call looks like this:

$('#new_record').submit(function(event) {
var form_data = $('#new_record').serialize();
  url: '<?php echo base_url(); ?>admin/insert_record/',
  type: "POST",
  data: form_data,
  success: function(msg)
    alert('Success: ' + msg);
return false;

This kind of AJAX call cannot be used for sending file data, as it uses the XMLHttpRequest protocol which obviously cannot handle POST data of type 'file'.

So one is in for a bunch of weird hacks.

Does anyone know of a solution where I can both send data (from an ajax loaded view in a div) and get info back from the server into the same div?

I've been scratching my head for days trying to implement a dozen different solutions, but none seem to take into account, that using an ajax solution for file upload would tell them that then you might have this kind of setup in the first place.

So put simple:
How do upload file to server, and get response back into the same div the upload came from - that is NOT REFRESH the whole page (THE BLEEDIN' POINT OF AJAX!!!)

[eluser]Stefan Hueg[/eluser]
Are you kidding...? We all gave you sufficient information in the other thread.


[eluser]Sven Delle[/eluser]
NO, I'm absolute not kiddin', why would you think that!? I'm still here in the forums asking this question, because it's simply not possible (as far as I've tested) to implement ANY of the solutions the way i want: in a two div setup where I constantly load views into ONE SINGLE DIV ON THE RIGHT.

I HAVE made it post as a 'normal' form. But that's not what I'm asking.

So I need to post a form from one view loaded into a div, and get feedback back into that view from the server (in my case to create a thumbnail from the newly uploaded image). I've spent days now trying to figure this out. And still no luck, no matter how much info you've provided.

[eluser]Sven Delle[/eluser]
I've implemented 6 different AJAX solutions now. And ALL can post files to the server. But NONE will work without a complete page refresh when calling a controller from a div with an AJAX loaded form.

I thought AJAX was about endless loading of content in divs. But obviously not when it comes to posting files to the server.

Am I the ONLY one in the whole world working with a setup like this?

Someone please prove me wrong.

[eluser]Sven Delle[/eluser]
OK, does anyone know of any technique to push info from the server to a client?

That would be nice to be able to do after a file upload finished ...

Maybe you need to use this in your Controller:
if ($this->input->is_ajax_request() == TRUE)
    // gee it's an ajax request!
    // gee it's a controller request!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.