derek5. 2017-11-19 19:20 采纳率: 100%
浏览 18

JQuery AJAX调用出现问题

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?