There are several inputs with the file type. How to make a file upload window appear after file upload?

  • receive a response from the server that the file was successfully uploaded and display a window through the Ajax so that the page does not reload - lexxl
  • the file is not transferred to the server, it is just a regular input, you just need to show that the file is in the input. - Dimangry
  • Those you want after the file is selected, the script would show it? not uploading to the server. html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files here is very well addressed this issue - lazyproger
  • I propose to correct the issue, since the question itself and the author’s comment are not the same. - Valery Gorbunov

1 answer 1

And again AJAX:

var fileData = $("#file-input").prop("files")[0]; var formData = new FormData(); formData.append("file", fileData); $.ajax({ url: 'load', type: 'POST', data: formData, cache: false, contentType: false, processData: false, success: function (data) { alert("Данные успешно загружены"); }, error: function () { alert("Произошел сбой бла бла бла"); } }); 
  • Bad code, and where does the error? at error the file may not load? - lazyproger
  • @ Dmitry Prikhodchenko, this is an event. If success is indicated by the message success , the error is error . - Telion
  • @ Dmitriy Prikhodchenko error will be, for example, if the address specified in the url is unavailable or for example returns 500 error - tCode
  • @Levelleor and what? 1. The question is different 2. I can upload the file and give the error. 3. Are you sure that this code will flood the file? - lazyproger
  • @ Dmitry Prikhodchenko you can’t choose when to make a mistake. It works when the server responds with an error code automatically. For example, 404, but when success returns 200. - Telion