I am not very well versed in JavaScript, but I want a multiple file upload form with a single submit button, no auto upload that would send all added files in a single request and provide a "complete" event that would be triggered when server returns some response. I found mootools form upload which seems to fit the bill, but handling onComplete Form.Upload event, I don't know how to tell whether upload has succeeded or failed. My backend will perform validation of uploaded files and reply with 200 if the files are OK or 500 Bad Request otherwise. Please suggest either how to handle (or modify) an onComplete event or another form that would meet my requirements.
Fooling around at night, I found a solution. In Form.Upload.js file on line 70 instead of Array.slice(arguments)
I pass this
(which happens to be Request.File) as a second argument into self.fireEvent
. Form.Upload onComplete event handler becomes a function of one argument, which is Request.File we passed into fireEvent
. It has a status
property which contains status code and a response
object with text
property which contains response body. So I compare a status code with 200 and display an alert with response.text. In case you want to analyze the response more deeply, Requst also has an xhr
property, which is -- you guessed it -- a plain old XmlHttpRequest.