[ https://issues.apache.org/jira/browse/WICKET-6517?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16336698#comment-16336698 ]
ASF GitHub Bot commented on WICKET-6517: ---------------------------------------- Github user andruhon commented on the issue: https://github.com/apache/wicket/pull/256 Another interesting neuance: I didn't find a way to cancel a request before it was actually sent, Imagine I do drag and drop of multiple files and jquery uploads them one by one. Normally with jQuery it is possible to return false from `beforeSend` handle to cancel the request, however it's not a case with wicket's `bsh`. I could do something like this: ```JavaScript Wicket.Ajax.ajax({ u: attrs.u, m: 'POST', mp: true, bsh: [ function (attributes, jqXHR, settings) { settings.xhr = function () { try { if (uploadContext.cancelled) { // cancel upload return null; } if (uploadContext.item) { /* Add progress indicator */ xhr.upload.addEventListener("progress", function (e) { var progress = Math.round(e.loaded / e.total * 100); onUploadProgress(uploadContext, attrs, progress); }); } return xhr; } catch (e) { } } } ], ``` However it will cause the jQuery.send to explode with `Cannot read property 'open' of null` I'm not sure what the best way to do that, but probably `_executeHandlers` could return false if any of handlers returns false, something like this: ```JavaScript /** * A helper function that executes an array of handlers (before, success, failure) * * @param handlers {Array[Function]} - the handlers to execute * @private */ _executeHandlers: function (handlers) { if (jQuery.isArray(handlers)) { // cut the handlers argument var args = Array.prototype.slice.call(arguments).slice(1); // assumes that the Ajax attributes is always the first argument var attrs = args[0]; var that = this._getTarget(attrs); for (var i = 0; i < handlers.length; i++) { var handler = handlers[i]; var r; if (jQuery.isFunction(handler)) { r = handler.apply(that, args); } else { r = new Function(handler).apply(that, args); } if (r === false) { return false; } } } }, //... ``` and ```JavaScript // execute the request var jqXHR = jQuery.ajax({ url: url, type: attrs.m, context: self, processData: wwwFormUrlEncoded, contentType: wwwFormUrlEncoded, beforeSend: function (jqXHR, settings) { if(self._executeHandlers(attrs.bsh, attrs, jqXHR, settings)===false) { return false; } we.publish(topic.AJAX_CALL_BEFORE_SEND, attrs, jqXHR, settings); if (attrs.i) { // show the indicator Wicket.DOM.showIncrementally(attrs.i); } }, // ... ``` > use Ajax for multipart instead of iframe > ---------------------------------------- > > Key: WICKET-6517 > URL: https://issues.apache.org/jira/browse/WICKET-6517 > Project: Wicket > Issue Type: Improvement > Components: wicket > Affects Versions: 8.0.0-M8 > Reporter: Sven Meier > Assignee: Sven Meier > Priority: Minor > > As Andrew Kondratev has pointed out on > https://github.com/apache/wicket/pull/255, we can use FormData to send > multipart data via Ajax. This makes the current iframe workaround obsolete. > Advantages: > - real Ajax !!1!!! > - we can drop a lot of code in wicket-ajax-jquery.js > - users can use Wicket.Ajax to send files as extra parameters, as requested > in pull request #255 > FormData is supported in Edge and IE 10. I'm not sure whether we still > support older browsers, but as fallback users can > - continue using Wicket 7 (supported for the next years) > - switch to non-Ajax uploads > - use a polyfill for FormData (several available on github) -- This message was sent by Atlassian JIRA (v7.6.3#76005)