Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 931083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:26:37+00:00 2026-05-15T20:26:37+00:00

Im doing a $.getJson call which I want to be able to reuse for

  • 0

Im doing a $.getJson call which I want to be able to reuse for different ui rendering.
I want to use the GetUserRoles(userName) method for rendering 2 ui controls with 2 different calls. The first call is made to populate a dropdownlist. Now I want to make another call to the method which will draw a UL list on the same page. How do I do it using the same method.

 function GetUserRoles(userName) {
            var param = { userName: userName };
            $.getJSON(userRoleController, param, function (data) { GetUserRolesSuccess(data, userName); });
        }

        function GetUserRolesSuccess(data,userName) {
            $("#userdetails #roles").html("");
            if (data.length != 0) {
                var roles = "<table class='rolesTable' cellpadding='0' cellspacing='0' border='0'>";
                for (var i = 0; i <= data.length - 1; i++) {
                    if (data[i] != undefined) roles += "<tr><td>" + data[i] + "</td><td><a href='#' onclick=\"RemoveUserFromRole('" + data[i] + "','" + userName + "');\">Remove</a></td></tr>";
                }
                roles += "</table>";
            }
            else {
                roles = "<p class='norolesavailable'>No roles assigned to user.</p>";
            }

            $("#userdetails #roles").html(roles); 
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:26:38+00:00Added an answer on May 15, 2026 at 8:26 pm

    Add a parameter to GetUserRoles and GetUserRolesSuccess which indicates the type of control to render, so the method signatures look like GetUserRoles(userName, controlToRender) and GetUserRolesSuccess(data, userName, controlToRender). Modify GetUserRoles to look like:

     function GetUserRoles(userName, controlToRender) {
         var param = { userName: userName };
         $.getJSON(userRoleController, param, function (data) { GetUserRolesSuccess(data, userName, controlToRender); });
     }
    

    and finally add a condition which renders a control based on the new parameter, e.g.:

    function GetUserRolesSuccess(data, userName, controlToRender) {
        if(controlToRender == 'ul') {
            // make a ul
        } else if(controlToRender == 'whatever') {
            // make a whatever
        }
    }
    

    Now simply call GetUserRoles passing in your new argument, e.g.:

    GetUserRoles('Jeff123', 'ul');
    GetUserRoles('Jeff123', 'foo');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery's $.ajax method to call getjson.php which returns a JSON object using
I'm doing a couple of .getJSON calls and if any one of them succeeds,
I'm doing the following jQuery call: $.getJSON( http://localhost:9000/user?name=, test, function(data) { alert(data.aaData[0]);} ); but
I'm doing a batch of getJSON() calls within a loop. When the calls succeed
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
I have the code below that shows a throbber and makes a getJSON call
I made a small example HTML page to get JQuery's getJSON method working. It
I'm trying to use JQuery's $.getJSON to access Model data from the Controller, and
My Django view method is below. I want to pass place_data as a response
I have a very simple asp.net mvc3 app that uses jquery::getJSON to call into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.