Hi Team
I have search tab, works fine but now i want to figure out once that data gets retrieved from the active directory. It must displayed to the table body(DisplayName, EmailAddress, Department columns here).
// ajax call
JavaScript
Select People and Groups
×
Search
Details
Display Name
E-mail Address
Title
Department
Presence
Work Phone
Location
$(document).ready(function () {
// Function to handle search button click event
$('#searchButton').on('click', function () {
var searchTerm = $('#searchInput').val().trim();
if (searchTerm !== '') {
// Send an AJAX request to the controller action to search for users
$.ajax({
url: '@Url.Action("SearchUsers", "Home")',
type: 'POST',
dataType: 'json',
data: { searchTerm: searchTerm },
success: function (data) {
// Clear previous search results
$('#userTable tbody').empty();
// Iterate through the retrieved user details and append them to the table
$.each(data, function (index, user) {
var row = '' +
'' + user.DisplayName + '' +
'' + user.Email + '' +
'' + user.Title + '' +
'' + user.Department + '' +
'' + user.Presence + '' +
'' + user.WorkPhone + '' +
'' + user.Location + '' +
'';
$('#userTable tbody').append(row);
});
// Show the modal with search results
$('#checkDetailsModal').modal('show');
},
error: function (jqXHR, textStatus, errorThrown) {
// Handle error if any
console.error('Error:', textStatus, errorThrown);
}
});
}
});
});
Amit MohantyRank #112 · 20K reputationPosted Mar 1, 2024, 6:08 AM EST
Add the id="userTable" attribute to your
Mithilesh TataRank #862 · 2.6K reputationPosted Mar 1, 2024, 5:49 AM EST
To pass data to a table using AJAX (Asynchronous JavaScript and XML), you typically fetch the data from a server-side endpoint (e.g., an API) and then dynamically populate the table with the retrieved data. Here's a basic example of how you can achieve this using jQuery and AJAX:
HTML:
Table Data with AJAX ID Name Email $(document).ready(function() { // AJAX request to fetch data $.ajax({ url: 'your-api-endpoint-url', type: 'GET', dataType: 'json', success: function(data) { // Iterate over the retrieved data and populate the table $.each(data, function(index, item) { $('#data-table tbody').append( ` ${item.id} ${item.name} ${item.email} ` ); }); }, error: function(xhr, status, error) { console.error('Error fetching data:', error); } }); });In this example:
'your-api-endpoint-url'with the URL of your server-side endpoint that returns the data in JSON format.$.ajax()function from jQuery. It's a GET request expecting JSON data.successcallback function populates the table dynamically by iterating over the data array and appending rows to the table body ().- If an error occurs during the AJAX request, the
Know the answer? Forums 01
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.Join Full leaderboard → 2026
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegistererrorcallback function logs the error to the console.Ensure that your server-side endpoint returns the data in the expected JSON format. Adjust the table structure and data population logic according to your specific requirements and the structure of your data.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts