weixin_33743661 2018-10-01 01:01 采纳率: 0%
浏览 152

Ajax调用后未定义

I have an ajax function that returns data and I want to push the objects name into an array but when I check the console, it keeps saying undefined. How can I print the certain attribute only?

$.ajax({
      url: 'http://localhost:3000/list',
      type: 'get',
      success: function(response){
        console.log(response);
        console.log(response.name);
      },
      error: function(){
        console.log('err');
      }
    });

When I check the results on console

//console.log(response);
(3) [{...}, {...}, {...}]
1: {_id: "1", name: "a"}
2: {_id: "2", name: "b"}
3: {_id: "3", name: "c"}

//console.log(response.name);
(3)undefined
  • 写回答

3条回答 默认 最新

  • weixin_33749131 2018-10-01 01:03
    关注

    Your response is an object so you must identify the index of what you want to display

      console.log(response[1].name); //will display "b"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据