Download Ajax File

I have a form that uploads a file, I process the inline file using ajax, but I do not know how I can get data using ajax.

In my script, I use this method:

 $.ajax(
            {
                type:    "POST",
                url:     "upload.php",
                data:    ({ file : '???' }),
                success: function(msg)
                {
                    $('#upload_box').html(msg);
                }
            });

How can I declare a file 'file' to receive file data? (file name, tmp_name, type, size, etc.).

+3
source share
3 answers

You cannot do this with the standard AJAX request. The most common solution is to publish the file in a hidden iFrame, as shown in this tutorial .

Since you are using jQuery, you can find the useful AJAX Upload library .

+2

, php script, , ,

            //In your onUpload callback
            var req = createRequest();
            req.open("GET", 'upload.php?file=' + filename,true);

            req.send(null);
            //Do your status checking
            var filetext= req.responseText;

, , , , javascript PHP.

+2

I decided to use the jQuery Form plugin ( http://malsup.com/jquery/form/ )

0
source

Source: https://habr.com/ru/post/1725680/


All Articles