How to send a file to the server using JSON and jQuery

I have to send the file to my server using jQuery. How can I do this using JSON?

The file type is not important, I intend to get byteArray or something similar on my server application.

If this helps, I am using an ASP.NET application, but my problem is not how I handle this on the server side, the problem is how to send the file data using jQuery.

I found some download plugins for jQuery that use the Flash file, others that do not use Flash, but I really want to know how this process works, and not just use something already created by someone!

+5
source share
5 answers

jQuery is JavaScript. I think you want to send data via Ajax, which cannot be done. The best you can do is use an iframe on the page, which uploads the file to a temporary directory (and not by default), and then returns information to the parent page about where the file is saved, and then you use it.

Unable to upload file to server using Ajax. This is too uncertain.

I cancel the expression above NOW

Now you can send / download the file date using Javascript, which is very difficult for a beginner to understand, but now this is possible in contrast to the answer to this question.

Using HTML5 file upload using AJAX and jQuery

+4
source

AJAX. HTTP- (POST). jQuery, , Flash, Java, iframe, POST iframe, .

+2

HTTP- $.ajax, , json. HTTP-, (type="file"). , .

+1

$.ajaxFileUpload(http://www.phpletter.com/Demo/AjaxFileUpload-Demo/), ASP.NET MVC,

  public ActionResult UploadFiles(List<HttpPostedFileBase> uFile)

$.ajaxFileUpload:

  $.ajaxFileUpload
(
    {
        url: "/Controller/UploadFiles", 
        secureuri: false,
        fileElementId: 'uFile', // the id of the file input controls holding the references to the files
        dataType: 'json',
        success: function (data, status) {
            // needs to handle the json return
        },
        error: function (data, status, e) {
            // same as error
        }
    }
)

.

+1

valum . , HTML5, โ€‹โ€‹ FileReader .. "AJAX".

https://stackoverflow.com/search?q=valums

: , - , , , . , , .

-2

All Articles