Last active
December 16, 2015 19:39
-
-
Save tamboer/5487176 to your computer and use it in GitHub Desktop.
jQuery ajax to get staff from selected department
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| $date_from = $('#date_from').val();$date_to = $('#date_to').val();$source = ''; | |
| $('#teamSelector').change(function(){ | |
| $selected_team = $(this).val(); | |
| $.ajax({ | |
| url : $baseUrl + "/public/staff/staff/return-json-staff", | |
| type : "POST", | |
| data : 'selected_team='+$selected_team+'&date_from='+$date_from+'$date_to='+$date_to+'&source='+$source | |
| }).done(function($response){ | |
| var obj = jQuery.parseJSON($response); | |
| $element = $('<select name="staff" id="staff">'); | |
| $element.append('<option value="all"></option>'); | |
| for(var x in obj){ | |
| console.log(x) | |
| $element.append('<optgroup label="' + x + '">'); | |
| for(var y in obj[x]){ | |
| $element.append('<option value="' + y + '">' + obj[x][y] + '</option>') | |
| } | |
| $element.append('</optgroup>'); | |
| } | |
| $element.append('</select>'); | |
| $('#staffSelectContainer').html($element); | |
| }) | |
| }) | |
| }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment