ajax.php 855 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. if (is_ajax()) {
  3. // if (isset($_POST["venue"]) && !empty($_POST["venue"])) { //Checks if action value exists
  4. // $action = $_POST["action"];
  5. // switch ($action) { //Switch case for value of action
  6. // case "test":
  7. test_function();
  8. // break;
  9. //}
  10. // }
  11. }
  12. //Function to check if the request is an AJAX request
  13. function is_ajax()
  14. {
  15. return True;
  16. // return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  17. }
  18. function test_function()
  19. {
  20. $return = $_POST;
  21. //Do what you need to do with the info. The following are some examples.
  22. //if ($return["favorite_beverage"] == ""){
  23. // $return["favorite_beverage"] = "Coke";
  24. //}
  25. $return["favorite_restaurant"] = "McDonald's";
  26. $return["json"] = json_encode($return);
  27. echo $_GET['callback'] . '(' . json_encode($return ). ')';
  28. }