开发者

Is it possible to upload files via Ajax?

开发者 https://www.devze.com 2023-02-25 17:50 出处:网络
I want to build a file manager for my ASP.NET MVC app and am curious if it\'s possible to upload files via ajax. I heard it was not possible and that you had to use flash.

I want to build a file manager for my ASP.NET MVC app and am curious if it's possible to upload files via ajax. I heard it was not possible and that you had to use flash.

So far in my travels I stumbled upon this demo: http://aquantum-demo.appspot.com/file-upload

It looks like a pretty solid file uploader that uses jQuery. Does this use flash at all to accomplish its goal? What are your opinions on the plugin I jus开发者_JAVA技巧t linked?

I have heard a lot about Uploadify, would that be a better choice?

Sorry, I'm new to the file uploading arena.


The answer to your question is no but there are jquery plugins that allow you to achieve this using an iframe behind the scenes.


No, but you could embed an iframe. This solution will look like uploading a file using AJAX (without refreshing the page).


You can use the HTML5 file API (If your using a competent browser).

var reader = new FileReader();

reader.readAsBinaryString(file);

reader.onload = function(string) {
    $.post(url, string, function() {
         // success
    }); 
};


You can use Uploadify, as you suggest, or ajaxupload, which is also a good choice. I use them both, and they are both good components.


in regards to ajax, the answer is no, the JavaScript framework does not support uploading files, although this is something to look out for in the future of HTML5, Sockets and Binary FileReaders etc.

For the mean time you can use a flash uploader, this would allow you to upload a file without changing the context of the page.

it will also allow you to interact with the web page, so when the file is uploaded you can then send a command to the page to execute a java script function, in turn would modify the page itself.

i would look at Uploadify which uses a flash up loader and was designed to be fully interactive with jQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消