簡體   English   中英

如何在不刷新當前頁面的情況下獲得 api 響應

[英]How can i get api response without refreshing the current page

我正在使用下面的 API 從我的數據庫中獲取當前聊天,問題是 api 運行良好,但問題是我每次都必須刷新我的頁面才能看到新的聊天,所以我不想要那個,關於如何獲取的任何建議沒有刷新的新聊天,請參閱下面的代碼

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);

//使用此代碼,無需重新加載當前頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM