I want to get data from a mongoose database and display it on a web page. However, my AJAX call isn't working and I don't know why. The code for the AJAX call is:
//THIS SECTION OF THE CODE IS FOR A JQUERY FADE-IN EFFECT.
$(function () {
console.log('button', $('.solarsystem'));
$('.solarsystem').on('click.fadeInPlanets', function(){
console.log('clicked');
$('div.hidden').fadeIn(5000).removeClass('hidden');
});
//THIS SECTION OF THE CODE IS FOR THE AJAX CALL.
function errorHandler(error){
console.error(error);
}
$.ajax({
url: '/planetstats'
}).done(function(response){
console.log(response);
}).fail(errorHandler);
});
When I load the page where I want the data to appear, I get the following error message:
Failed to load resource: the server responded with a status of 404 (Not Found)
The strange thing is that when I make a GET request using Postman, it displays all the information as it should. As I understand it, if I can make a GET request using Postman I should be able to make the same GET request using AJAX with the code I've written above, but it's just not working. Any help you could provide would be extremely welcome. Many thanks.