Commit 8af347bd authored by Tino Goratsch's avatar Tino Goratsch

Extended the ajax-form jQuery plugin with the ability to gracefully handle failed AJAX requests

parent 25abe397
......@@ -140,40 +140,47 @@
contentType: processData ? 'application/x-www-form-urlencoded; charset=UTF-8' : false,
beforeSend: function () {
self.showLoadingLayer();
},
success: function (responseData) {
try {
if (responseData.redirect_url) {
window.location.href = responseData.redirect_url;
} else {
var $content = $(self.settings.targetElement),
offsetTop = $content.offset().top;
// Scroll to the beginning of the content area, if the current viewport is near the bottom
if ($(document).scrollTop() > offsetTop) {
$('html, body').animate(
{
scrollTop: offsetTop
},
'fast'
);
}
}
}).done(function (responseData) {
try {
if (responseData.redirect_url) {
window.location.href = responseData.redirect_url;
} else {
var $content = $(self.settings.targetElement),
offsetTop = $content.offset().top;
// Scroll to the beginning of the content area, if the current viewport is near the bottom
if ($(document).scrollTop() > offsetTop) {
$('html, body').animate(
{
scrollTop: offsetTop
},
'fast'
);
}
if (responseData.success === false) {
self.handleFormErrorMessages($form, responseData.content);
} else {
$content.html(responseData);
if (responseData.success === false) {
self.handleFormErrorMessages($form, responseData.content);
} else {
$content.html(responseData);
if (typeof hash !== "undefined") {
location.hash = hash;
}
if (typeof hash !== "undefined") {
location.hash = hash;
}
}
} catch (err) {
console.log(err.message);
} finally {
self.hideLoadingLayer();
}
} catch (err) {
console.log(err.message);
} finally {
self.hideLoadingLayer();
}
}).fail(function (jqXHR, textStatus, errorThrown) {
self.hideLoadingLayer();
if (jqXHR.responseText.length > 0) {
document.open();
document.write(jqXHR.responseText);
document.close();
}
});
},
......
......@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] - 20016-xx-xx
### Added
- Extended the ajax-form jQuery plugin with the ability to gracefully handle failed AJAX requests
### Changed
- Reworked and improved the form handling a little bit
- Updated the CKEditor WYSIWYG-Editor to version 4.6
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment