From e20626f1ad1831d5286708bba3f4623d30bccec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvidas=20Sipavi=C4=8Dius?= Date: Wed, 2 Sep 2015 17:53:57 +0300 Subject: [PATCH] Expose jQuery deferred XHR object for access to promises --- assets/js/src/ajax.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/js/src/ajax.js b/assets/js/src/ajax.js index 06a2c86a6b..adc251e1e8 100644 --- a/assets/js/src/ajax.js +++ b/assets/js/src/ajax.js @@ -13,13 +13,13 @@ define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { onError: function(xhr, textStatus, errorThrown) {} }, get: function(options) { - this.request('get', options); + return this.request('get', options); }, post: function(options) { - this.request('post', options); + return this.request('post', options); }, delete: function(options) { - this.request('delete', options); + return this.request('delete', options); }, init: function(options) { // merge options @@ -46,18 +46,18 @@ define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { endpoint: this.options.endpoint, method: this.options.action, data: this.options.data || {} - }; + }, jqXHR; // make ajax request depending on method if(method === 'get') { - jQuery.get( + jqXHR = jQuery.get( this.options.url, params, this.options.onSuccess, 'json' ); } else { - jQuery.ajax({ + jqXHR = jQuery.ajax({ url: this.options.url, type : 'post', data: params, @@ -69,6 +69,8 @@ define('ajax', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { // clear options this.options = {}; + + return jqXHR; } }; });