weixin_33682719 2018-08-07 08:09
浏览 21

从xml接收单个数据

I have brought some data from the server using ajax. Now I want to, not bring all the data, only the name is inter. How can I do this? that my code

const url = 'https://jsonplaceholder.typicode.com/users'

const xhr = new XMLHttpRequest()

xhr.onreadystatechange = () => {
    console.log(xhr.response);
}
xhr.open('GET', url)
xhr.send()
  • 写回答

1条回答 默认 最新

  • weixin_33743248 2018-08-07 08:17
    关注

    You could loop through the xhr response and get the name of the users.

       xhr.onreadystatechange = () => {
         if(xhr.response) {
           let userResponse = JSON.parse(xhr.response);
           for (index in userResponse) {
               console.log(userResponse[index].name);
           }
         }
       }
    

    You can even save it in a temporary variable and make further manipulations.

    But if you meant bringing just the name from the server, it is not possible unless the server exposes an API to do so.

    If you have access to the server you could create an API to do this. But, if your server had used graphQL, it is possible to make queries while making API requests like you asked for.

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3