Procházet zdrojové kódy

Added primitive ajax.php for testing

Foppe Hemminga před 6 roky
rodič
revize
376ea2a386
3 změnil soubory, kde provedl 36 přidání a 3 odebrání
  1. 32 0
      ajax.php
  2. 2 1
      composer.json
  3. 2 2
      index.php

+ 32 - 0
ajax.php

@@ -0,0 +1,32 @@
+<?php
+
+if (is_ajax()) {
+	if (isset($_POST["venue"]) && !empty($_POST["venue"])) { //Checks if action value exists
+		// $action = $_POST["action"];
+		// switch ($action) { //Switch case for value of action
+		//	case "test":
+				test_function();
+		//		break;
+		//}
+	}
+}
+
+//Function to check if the request is an AJAX request
+function is_ajax()
+{
+	return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
+}
+
+function test_function()
+{
+	$return = $_POST;
+
+	//Do what you need to do with the info. The following are some examples.
+	//if ($return["favorite_beverage"] == ""){
+	//  $return["favorite_beverage"] = "Coke";
+	//}
+	//$return["favorite_restaurant"] = "McDonald's";
+
+	$return["json"] = json_encode($return);
+	echo json_encode($return);
+}

+ 2 - 1
composer.json

@@ -1,6 +1,7 @@
 {
   "require": {
     "vlucas/phpdotenv": "3.3.x-dev",
-    "ext-pdo": "*"
+    "ext-pdo": "*",
+    "ext-json": "*"
   }
 }

+ 2 - 2
index.php

@@ -47,7 +47,7 @@
             <!-- <th>id</th> -->
             <th>venue</th>
             <th>state</th>
-            <th>race_date</th>
+            <th>date</th>
             <th>race</th>
             <th>start</th>
             <th>utc</th>
@@ -87,7 +87,7 @@ TABLEFOOT;
 			}
         ?>
     <tr>
-        <!-- <td><?php echo htmlspecialchars($row['id']); ?></td> -->
+        <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
         <td><?php echo htmlspecialchars($row['venue']); ?></td>
         <td><?php echo htmlspecialchars($row['state']); ?></td>
         <td><?php echo htmlspecialchars($row['race_date']); ?></td>