February 28, 2012

How to upload a file using a simple jquery-ajax call

Question by Alon

I am searching for a simple client-side script to upload a file using ajax.
Searching for the web for this script only brought up a lot of plugins with multi-features. I don’t need multi-feautres – just to be able to upload it as simple as possible using ajax

Is it possible to write something simple as:

$.get('server/upload.php?file = ' + $('#uploadInput').val(), function(data) {
   $('.result').html(data);    
 });

If it is possible – how should I write it right ($('#uploadInput').val() won’t give me the right directory path – so what do I need to do to pass the location using Ajax).

aside from that – in order to get drag&drop for files – Is there a simple script for that or do I need to use plugin (and is there a really tiny and simple one without multi-features)

Answer by Starx

Uploadify is another great solution for ajax upload. Its

  • extremely easy to setup,
  • very stylish, and
  • cross broswer.

See demos

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!