Struggling to Resolve JavaScript Error in Backend Implementation: Need Assistance

I’m encountering an issue with the JavaScript code on my website, and I’m seeking assistance in resolving it. The problem arises when attempting to implement a dynamic dropdown menu for selecting gold rates based on different locations. Despite following tutorials and debugging extensively, the dropdown menu fails to populate with the expected data, leaving it blank. I suspect there might be an issue with the AJAX request or the data parsing process, but I’m having trouble pinpointing the exact cause. Can anyone provide guidance or suggest potential solutions to troubleshoot and fix this issue? I’m open to any insights or recommendations. Thank you in advance for your help!

` // JavaScript code for dynamic dropdown menu on findgoldrate.com

 // Function to fetch gold rates based on location
 function fetchGoldRates(location) {
 // AJAX request to fetch gold rates data
 $.ajax({
 rl: '/api/gold-rates',
 method: 'GET',
 data: { location: location },
 success: function(response) {
 // Parse response and populate dropdown menu
 var dropdownMenu = document.getElementById('gold-rates-dropdown');
 dropdownMenu.innerHTML = ''; // Clear existing options

 // Loop through response data and create option elements
 response.forEach(function(rate) {
 var option = document.createElement('option');
 option.value = rate.value;
 option.text = rate.location + ': $' + rate.value;
 dropdownMenu.appendChild(option);});},
 error: function(xhr, status, error) {
 console.error('Error fetching gold rates:', error);
 }
 });
 }
 // Function to initialize dropdown menu
 function initDropdownMenu() {
 // Event listener for location change
 var locationInput = document.getElementById('location-input');
 locationInput.addEventListener('change', function() {
 var selectedLocation = locationInput.value;
 fetchGoldRates(selectedLocation);
 });
 }
 // Initialize dropdown menu when DOM is ready
 document.addEventListener('DOMContentLoaded', function() {
 initDropdownMenu();
 });

`

What I’ve tried so far:

Ensured that the AJAX request is correctly configured and reaching the server at the specified endpoint (/api/gold-rates).
Verified that the response data is properly formatted and accessible.
Checked for any errors in the browser console, but no specific errors are being reported.