Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is my parser file...
- <?php
- //it grabs the init file, wherever it is located relative to the parser file itself
- require_once '../users/init.php';
- //it instantiates the DB
- $db = DB::getInstance();
- //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.
- $task_id = Input::get('task_id');
- $checked = Input::get('checked');
- $user_id = ($checked)?$user->data()->id : 0;
- $username = $user->fullName(); // this is a custom function, but essentially it is the user's first/last name
- //then the db is updated
- $db->update('kitchen_tasks',$task_id,['user'=>$user_id]);
- //a response is sent
- $response = ['success'=>true,'user_name'=>$username,'task_id'=>$task_id,'checked'=>$checked];
- echo json_encode($response);
- die;
- 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.
- <script>
- function handleTaskCheck(evt){
- // data-* attributes are accessed by evt.target.dataset.*
- if(evt.target.checked === true){
- taskCount++;
- } else {
- taskCount--;
- }
- jQuery.ajax({
- url:"parsers/kitchen_tasks.php",
- method:"POST",
- data:{task_id:evt.target.dataset.id,checked:evt.target.checked},
- success: taskUpdateSuccess
- });
- jQuery('#taskCount').html(taskCount);
- }
- function taskUpdateSuccess(resp){
- var r = JSON.parse(resp);
- if(r.success){
- if(r.checked === "true"){
- jQuery('#assignedUser_'+r.task_id).html(" "+r.user_name);
- } else {
- jQuery('#assignedUser_'+r.task_id).html("");
- }
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement