AJAX framework
authorJoey Schulze <joey@infodrom.org>
Sun, 17 Jul 2016 11:28:21 +0000 (13:28 +0200)
committerJoey Schulze <joey@infodrom.org>
Sun, 17 Jul 2016 20:25:26 +0000 (22:25 +0200)
Styles/service.style
src/infodrom.js [new file with mode: 0644]

index 9b49130..9081fd6 100644 (file)
@@ -35,6 +35,7 @@
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 <link href="<root_prefix>infodrom.css" rel="stylesheet" type="text/css">
 <script type="text/javascript" src="<root_prefix>/jquery-2.1.0.min.js"></script>
+<script type="text/javascript" src="<root_prefix>/infodrom.js"></script>
 </head>
 <body>
 
diff --git a/src/infodrom.js b/src/infodrom.js
new file mode 100644 (file)
index 0000000..c27a86b
--- /dev/null
@@ -0,0 +1,27 @@
+function ajax_request(funcname, params, callback, error_callback)
+{
+    if (params === null)
+       params = 'func='+funcname;
+    else if (typeof params == 'object')
+       params['func'] = funcname
+    else if (typeof params == 'string')
+       params = 'func='+funcname+'&'+params
+    else
+       return false;
+
+    $.post('/ajax.php', params,
+          function(data){
+              if (!data.status) {
+                  if (typeof data.error == 'string')
+                      var error = data.error;
+                  else
+                      var error = 'An error occurred'
+                  alert(error);
+                  if (typeof error_callback == 'function')
+                      error_callback(data);
+                  return;
+              }
+              if (typeof callback == 'function')
+                  callback(data);
+          });
+}