Browse Source

Add deleteJSON

Volodymyr Tkach 2 years ago
parent
commit
ee0a4eeac3
1 changed files with 24 additions and 0 deletions
  1. 24 0
      js/ajax.js

+ 24 - 0
js/ajax.js

@@ -55,6 +55,30 @@ ajax.delete = function(url, data, callback, async) {
 	ajax.send(url + (query.length ? '?' + query.join('&') : ''), callback, 'DELETE', null, async);
 	ajax.send(url + (query.length ? '?' + query.join('&') : ''), callback, 'DELETE', null, async);
 };
 };
 
 
+ajax.deleteJSON = function(url, data, callbackSuccess, callbackError, async) {
+	ajax.delete(url, data, function(method, data, readyState, status, responseText) {
+		if(readyState == 4) {
+			if(status == 200) {
+				try {
+					var r = JSON.parse(responseText);
+					if(callbackSuccess) {
+						callbackSuccess(method, data, readyState, status, r);
+					};
+				} catch(e) {
+					if(callbackError) {
+						callbackError(method, data, readyState, status, e);
+					};
+				};
+			} else {
+				if(callbackError) {
+					var e = new AjaxErrorBadStatusCode('Bad status code '+status);
+					callbackError(method, data, readyState, status, e);
+				};
+			};
+		};
+	}, async);
+};
+
 ajax.get = function(url, data, callback, async) {
 ajax.get = function(url, data, callback, async) {
 	var query = [];
 	var query = [];
 	for(var key in data) {
 	for(var key in data) {