Replacing AJAX results when new items are clicked
Hey everyone.
Currently I have two functions that call endpoints in AJAX and they return json files with member information. These are seperated into two columns (Groups and Members) I can populate everything, however, what I want to happen is when a new different group is clicked, the old results are replaced with the new one instead of being added to the list, which is what is happening now.
- //Get JSON from LDAP for groups
- $(function displayGroupItems() {
- $('.group-submit').click(function(event) {
- $.ajax({
- url:'ldap/groups',
- method: 'GET',
- dataType: 'json',
- success: function(data) {
- $.each(data.groups, function(i, dn) {
- output = '<li class="dn-wrapper">' +'<span class="dn-class">'+ dn.dn +'</span>' + '</li>';
- $(output).appendTo('#dropdown');
- });
- }
- })
- });
- });
- $(function displayMemberItems() {
- $(document).on('click','.dn-class', function(event) {
- var textclass = $(this).text().replace("/=/g",'%3D').replace("/,/g", '%2C');
- $.ajax({
- url:'ldap/members/'+textclass,
- method:'GET',
- dataType: 'json',
- success: function(pull) {
- $.each(pull.members, function(u, uid) {
- content = '<span>'+uid+'</span>';
- $(content).appendTo('.ldap-users');
- });
- }
- })
- });
- });
-
I'm just not sure where to start. I was looking at replaceWith, but that doesn't seem to apply to this situation. I will paginate the results, just trying to get all the basic functions down first.
Thank you.