简体   繁体   中英

How can i get api response without refreshing the current page

I am using the below API to get current chats from my database , the thing is the api works well, but issue is i have to refresh my page each time to see new chats, so i dont want that, any suggestions on how to get new chats without refresh, see my code below

getChatsList() {
    this.api.post_private('v1/chats/getById', { room_id: this.roomId 
      }).then((data: any) => {
      console.log(data);
      if (data && data.status && data.status === 200 && data.data.length) {
        this.messageList = data.data;
      }
    }, error => {
      console.log(error);
    }).catch(error => {
      console.log(error);
    });
  }
function getChatsList() {
this.api.post_private('v1/chats/getById', { room_id: this.roomId 
  }).then((data: any) => {
  console.log(data);
  if (data && data.status && data.status === 200 && data.data.length) {
    this.messageList = data.data;
  }
}, error => {
  console.log(error);
}).catch(error => {
  console.log(error);
});
}
setInterval(getChatsList, 1000);

//Use this code, without reload current page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM