javascript - Can't add notice after xhr request. Rails -
The file is added and correct redirects, but without notice, if you do not use EXHOR, the notice shows.
application.js Administrator .bb When you make a simple request from the browser (using a When you do not change the current location of the If you want to communicate with the asynchronous server, and use your answers to the page's re-render, read it
var files = evt.target.files || Evt.dataTransfer.files; // files file is a filelist of the object to list some properties (var i = 0, f; f = files [i]; i ++) {var xhr = new XMLHttpRequest (); Xhr.open ("post", 'report_drag', wrong); Xhr.setRequestHeader ("content-type", "text / plain; charset = UTF-8"); Xhr.setRequestHeader ("X_FILENAME", "file." + F.name.split ('.'). Pop ()); Xhr.setRequestHeader ('X-CSRF- Token', $ ('meta [name = "CSRF-token"]'). Attr ('content')); Xhr.send (f); }
Diff report_ drag filename = "report / # {DateTime.now.year} - # DateTime .now.month} / "+" # vendor: where (id: current_user.id) .first.title} "+" # {file.extname ("# {request.headers ['HTTP_X_FILENAME']}")} "File. Open file (file name), "wb") {| F | | F.write (request.body.read)} redirect_to report_url, notice: "ФР° йл Ñ ?? Ñ ?? пÐμÑ ?? но Ð'оР± Ð ° вРÐμн. "End
link) or
button , or simply typing in the address bar), the response changes the current page and is rendered instead.
XHR , the browser does not render anything - it assumes that the caller (JavaScript code) is responsible for reading the response, And it's going to figure it out.
Comments
Post a Comment