简体   繁体   中英

Automatically loading new messages onto page

I have a message table that has a few columns such as id , to_id , from_id , is_read , etc. I'm looking for the most reliable way to check if there are any new emails and if there are, load them in with jquery and display them to the logged in user. I was thinking about using the is_read column and if its not read then pull it in but sometimes the user just wont open the message so I don't want to pull it in again. What is the best way to check for new messages? I just want new messages to load into the inbox if the user is sitting on the inbox page.

Automatically calling out is not a good idea. It creates a lot of overhead you don't need.

If you have your heart set on it,

<script>
    setInterval(function(){ <code here> }, 50);
</script>

Source

Otherwise, look at Pusher

Your API should accept either a last_message_id or a last_checked_at parameter, and only return messages which are newer than that id/timestamp. Client side, you should ask for messages which are newer than your newest message, or the messages at the "top" of the list.

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