Volodymyr Tkach 2 years ago
parent
commit
3b3d1171d2
1 changed files with 5 additions and 3 deletions
  1. 5 3
      js/ajax.js

+ 5 - 3
js/ajax.js

@@ -218,7 +218,7 @@ ajax.processFormSubmit = function(event) {
 			if(form.method == "post") { ajaxFunc = ajax.post; };
 			ajaxFunc(form.action, data, function(method, data, readyState, status, responseText) {
 				if(readyState == 4) {
-					var error = (status == 200);
+					var error = (status != 200);
 					var responseData = responseText;
 					try {
 						var responseData = JSON.parse(responseText);
@@ -259,7 +259,6 @@ ajax.processForms = function() {
 
 ajax.processCheckboxClick = function(event) {
 	if(!event) var event = window.event;
-	event.preventDefault();
 	var checkbox = event.target;
 	var on = checkbox.getAttribute('data-ajax-on');
 	var off = checkbox.getAttribute('data-ajax-off');
@@ -273,7 +272,7 @@ ajax.processCheckboxClick = function(event) {
 	box.className += " loading";
 	ajax.post(checkbox.checked ? on : off, {}, function(method, data, readyState, status, responseText) {
 		if(readyState == 4) {
-			var error = (status == 200);
+			var error = (status != 200);
 			var responseData = responseText;
 			try {
 				var responseData = JSON.parse(responseText);
@@ -285,6 +284,9 @@ ajax.processCheckboxClick = function(event) {
 			} catch(e) {
 				console.log('ajax.processCheckboxClick', 'e', e);
 			};
+			if(error) {
+				checkbox.checked = !checkbox.checked;
+			};
 			box.className = box.className.replace(new RegExp('(\\s|^)loading(\\s|$)'), ' ').trim();
 		};
 	});