diff options
| author | Christophe Matthieu <chm@odoo.com> | 2018-09-10 10:26:45 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2018-09-10 16:36:43 +0200 |
| commit | dabe5bfbae10de983bd1cbdba38949f17a62562e (patch) | |
| tree | 94731f1082ec869af188a805007bf9409274a4b4 /addons/web/static/src/js/services | |
| parent | 1199451606cab7342e34fc9c41a2085b8beb1243 (diff) | |
[FIX] web: ajax must return a promise with abort method
Remove part in service_mixins who hide this error. Queries must be able
to be canceled for better performance. Also in the case of longpolling,
if the request is not canceled, wait for a server message or the maximum
time (30 sec) to add or delete channels.
Diffstat (limited to 'addons/web/static/src/js/services')
| -rw-r--r-- | addons/web/static/src/js/services/ajax_service.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/addons/web/static/src/js/services/ajax_service.js b/addons/web/static/src/js/services/ajax_service.js index 3446f651a59..6c61fdbf9ed 100644 --- a/addons/web/static/src/js/services/ajax_service.js +++ b/addons/web/static/src/js/services/ajax_service.js @@ -8,17 +8,20 @@ var session = require('web.session'); var AjaxService = AbstractService.extend({ name: 'ajax', rpc: function (route, args, options, target) { - return $.Deferred(function (def) { - session.rpc(route, args, options).then(function () { - if (!target.isDestroyed()) { - def.resolve.apply(def, arguments); - } - }, function () { - if (!target.isDestroyed()) { - def.reject.apply(def, arguments); - } - }); - }).promise(); + var def = $.Deferred(); + var promise = def.promise(); + var xhrDef = session.rpc(route, args, options); + promise.abort = xhrDef.abort.bind(xhrDef); + xhrDef.then(function () { + if (!target.isDestroyed()) { + def.resolve.apply(def, arguments); + } + }).fail(function () { + if (!target.isDestroyed()) { + def.reject.apply(def, arguments); + } + }); + return promise; }, }); |
