src/ztfy/myams/resources/js/ext/jquery-jsonrpc.js
changeset 0 8a19e25e39e4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/myams/resources/js/ext/jquery-jsonrpc.js	Wed May 07 10:36:24 2014 +0200
@@ -0,0 +1,36 @@
+(function ($) {
+
+	$.jsonRpc = $.jsonRpc || function (options) {
+		options.type = options.type || 'GET';
+		var ajaxOptions = {
+			contentType: 'application/json',
+			dataType: options.type == 'GET' ? 'jsonp' : 'json',
+			processData: options.type == 'GET'
+		};
+
+		var data = {
+			version: options.version || '1.0',
+			method: options.method || 'system.listMethods',
+			params: options.params || []
+		};
+		$.each(data, function (i) {
+			delete options[i]
+		});
+
+		function send() {
+			options.data = JSON.stringify(data);
+			if (options.type == 'GET') options.data = {json: options.data};
+			$.ajax($.extend(ajaxOptions, options));
+		}
+
+		if (typeof JSON == 'undefined') {
+			$.getScript('http://www.json.org/json2.js', function () {
+				send()
+			});
+		} else {
+			send();
+		}
+		return $;
+	};
+
+})(jQuery);