Revert "Improve ajax errors [MAILPOET-929]"
This commit is contained in:
@@ -1,19 +1,5 @@
|
|||||||
function requestFailed(errorMessage, xhr) {
|
|
||||||
if (xhr.responseJSON) {
|
|
||||||
return xhr.responseJSON;
|
|
||||||
}
|
|
||||||
var message = errorMessage.replace("%d", xhr.status);
|
|
||||||
return {
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
||||||
|
'use strict';
|
||||||
MailPoet.Ajax = {
|
MailPoet.Ajax = {
|
||||||
version: 0.5,
|
version: 0.5,
|
||||||
options: {},
|
options: {},
|
||||||
@@ -58,6 +44,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
|
|||||||
|
|
||||||
// set request params
|
// set request params
|
||||||
var params = this.getParams();
|
var params = this.getParams();
|
||||||
|
var deferred = jQuery.Deferred();
|
||||||
|
|
||||||
// remove null values from the data object
|
// remove null values from the data object
|
||||||
if (_.isObject(params.data)) {
|
if (_.isObject(params.data)) {
|
||||||
@@ -67,14 +54,16 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ajax request
|
// ajax request
|
||||||
var deferred = jQuery.post(
|
deferred = jQuery.post(
|
||||||
this.options.url,
|
this.options.url,
|
||||||
params,
|
params,
|
||||||
null,
|
null,
|
||||||
'json'
|
'json'
|
||||||
).then(function(data) {
|
).then(function(data) {
|
||||||
return data;
|
return data;
|
||||||
}, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage')));
|
}, function(xhr) {
|
||||||
|
return xhr.responseJSON;
|
||||||
|
});
|
||||||
|
|
||||||
// clear options
|
// clear options
|
||||||
this.options = {};
|
this.options = {};
|
||||||
|
@@ -55,9 +55,6 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
|
|||||||
'mailpoet.js'
|
'mailpoet.js'
|
||||||
)%>
|
)%>
|
||||||
|
|
||||||
<%= localize({
|
|
||||||
'ajaxFailedErrorMessage': __('An error has happened while performing a request, the server has responded with response code %d'),
|
|
||||||
}) %>
|
|
||||||
<% block translations %><% endblock %>
|
<% block translations %><% endblock %>
|
||||||
|
|
||||||
<% block after_translations %><% endblock %>
|
<% block after_translations %><% endblock %>
|
||||||
|
Reference in New Issue
Block a user