Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. var status = $(this).prop("checked");
  2. var room_id = id;
  3. $.post('maintenanceControl.php', {action: status, id: room_id});
  4.  
  5. <?php
  6.  
  7. if (isset($_POST['action']) && !empty($_POST['action']) && isset($_POST['id']) && !empty($_POST['id'])) {
  8. $action = $_POST['action'];
  9. $id = $_POST['id'];
  10. if ($action) {
  11. return manageMaintenance($id, true);
  12. } else {
  13. return manageMaintenance($id, false);
  14. }
  15. }
  16.  
  17. function manageMaintenance($room_id, $status)
  18. {
  19. $jsonString = file_get_contents('status.json');
  20. $data = json_decode($jsonString, true);
  21.  
  22. foreach ($data['rooms'] as $key => $entry) {
  23. if ($key == $room_id) {
  24. $data[$key]['maintenance'] = $status;
  25. }
  26. }
  27.  
  28. $newJsonString = json_encode($data);
  29. file_put_contents('status.json', $newJsonString);
  30.  
  31. return true;
  32. }
  33.  
  34. $.post( "test.php", function( data ) {
  35. alert(data);
  36. });
  37.  
  38. <?php
  39. echo "test";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement