Advertisement
Guest User

Untitled

a guest
Feb 12th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. This is my parser file...
  2. <?php
  3. //it grabs the init file, wherever it is located relative to the parser file itself
  4. require_once '../users/init.php';
  5. //it instantiates the DB
  6. $db = DB::getInstance();
  7.  
  8. //in this example I am getting users to sign up for a certain task, so it is looking for the id of the task and the id of the user, which I passed to it from jquery.
  9. $task_id = Input::get('task_id');
  10. $checked = Input::get('checked');
  11. $user_id = ($checked)?$user->data()->id : 0;
  12. $username = $user->fullName(); // this is a custom function, but essentially it is the user's first/last name
  13.  
  14. //then the db is updated
  15. $db->update('kitchen_tasks',$task_id,['user'=>$user_id]);
  16.  
  17. //a response is sent
  18. $response = ['success'=>true,'user_name'=>$username,'task_id'=>$task_id,'checked'=>$checked];
  19. echo json_encode($response);
  20. die;
  21.  
  22. HERE is my javascript at the bottom of my userspice page... Most of the count stuff on the page is not important. It's just showing how many boxes are checked.
  23. <script>
  24.  
  25. function handleTaskCheck(evt){
  26. // data-* attributes are accessed by evt.target.dataset.*
  27. if(evt.target.checked === true){
  28. taskCount++;
  29. } else {
  30. taskCount--;
  31. }
  32.  
  33. jQuery.ajax({
  34. url:"parsers/kitchen_tasks.php",
  35. method:"POST",
  36. data:{task_id:evt.target.dataset.id,checked:evt.target.checked},
  37. success: taskUpdateSuccess
  38. });
  39.  
  40. jQuery('#taskCount').html(taskCount);
  41. }
  42.  
  43. function taskUpdateSuccess(resp){
  44. var r = JSON.parse(resp);
  45. if(r.success){
  46. if(r.checked === "true"){
  47. jQuery('#assignedUser_'+r.task_id).html(" "+r.user_name);
  48. } else {
  49. jQuery('#assignedUser_'+r.task_id).html("");
  50. }
  51. }
  52. }
  53.  
  54. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement