weixin_33704234 2019-05-22 13:52 采纳率: 0%
浏览 17

为什么忽略AJAX调用?

I don't know why the process ignores my AJAX call. It simply jumps from console.log("1"); to console.log("2");.

Can someone explain to me what is going wrong?

render: function() {
  let view = this;
  component.prototype.render.call(view);

  console.log("1");

  $.ajax = ({
    type: "GET",
    cache: false,
    url: "news.json",
    dataType: "json",
    success: function(json) {

      console.log("success");

      for (let i = 0; i < json.length; i++) {
        let news = modelNews;
        news.title = json[i].title;
        news.type = json[i].type;
        news.img = json[i].img;
        news.link = json[i].link;

        view.$('#newsfeed').append(news.getNewsFeedLook());
      }
    },
    error: function() {
      console.log("error");
    }
  });

  console.log("2");

}
  • 写回答

1条回答 默认 最新

  • 普通网友 2019-05-22 13:57
    关注

    Your code is not calling the ajax function of jQuery, it is reassigning it.

    $.ajax = ({
        type: "GET",
        cache: false,
        url: "news.json",
        dataType: "json",
        success: function(json) {
    
          console.log("success");
    
          for (let i = 0; i < json.length; i++) {
            let news = modelNews;
            news.title = json[i].title;
            news.type = json[i].type;
            news.img = json[i].img;
            news.link = json[i].link;
    
            view.$('#newsfeed').append(news.getNewsFeedLook());
          }
        },
        error: function() {
          console.log("error");
        }
      });
    

    This is the proper call, a function call that is. Pay closer attention to minor error like this!

    $.ajax({
        type: "GET",
        cache: false,
        url: "news.json",
        dataType: "json",
        success: function(json) {
    
          console.log("success");
    
          for (let i = 0; i < json.length; i++) {
            let news = modelNews;
            news.title = json[i].title;
            news.type = json[i].type;
            news.img = json[i].img;
            news.link = json[i].link;
    
            view.$('#newsfeed').append(news.getNewsFeedLook());
          }
        },
        error: function() {
          console.log("error");
        }
      });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊