I am familiar with jquery. I am trying to create a discussion forum where its content needs to be updated dynamically. I am doing it with jquery. but every time I try to update content of a division, I have to retrieve the whole data from database. Is there any simple way in which I can just add the updated data to the existing division? Can anybody suggest me a way? I really need help. Thanks in advance.
-
hey, have you seen math.stackoverflow.com. While we are viewing the page it prompts user to update the content saying that there are some posts with updated content. I need to know how to implement that functionality. How to compare the existing content with updated content? Any Ideas?– apparaokoppukaJul 1, 2013 at 14:55
2 Answers
There is a mechanism used by some site for "display more" feature. I use it to display items 10 by 10 with a "more" button. You can adjust it to be called on interval instead of a click event.
The idea is to put the id of the last displayed item in the ajax response. Call it lastId. Store it in an hidden input in your page. When you want to display new informations, send this id in the request. In your query, you have to write something like
select * from elements where element_id > lastId
It will gives you all new elements since the last request. (of course, you must have a strategy of auto increment or something like this).
Get the new higher Id and send it back in the ajax answer. Update lastId where you need it.
Repeat the operation to have new elements...
-
acutally, thats not my intention. If there is a post in the forum and some user is viewing it. I want to update the content of the post, if that post gets any replies while the user is viewing it. Is there any way other than retrieve the whole content periodically. Jul 1, 2013 at 14:41
-
No. I don't think so. The client can't know that there has been updates in the database and the server can't tell his client. I don't know how would react a browser if you send it a response but it hasn't have sent a request first. I think it will ignores the message from the serv.– TCHdvlpJul 1, 2013 at 16:20
-
is there any way to notify the user that the content of current division is updated prompt him to reload. Is there any way to compare the updated content and preloaded content? Or How to do it? Any suggestions... Jul 1, 2013 at 17:11
I don't know which language/framework do you use, but these videos (and corresponding resources) can be helpful: http://railscasts.com/episodes/260-messaging-with-faye, http://railscasts.com/episodes/229-polling-for-changes-revised
It describes how to poll for changes and how to use web sockets to solve this problem.
-
I am using php with jquery. Is there any answer other than videos. Cause, I work on slow internet connection. Jul 1, 2013 at 14:44
-
Well, you can have a look at Socket.IO: socket.io. I do not have any links to videos that describe how to implement this using PHP :(. Jul 1, 2013 at 14:47
-
hey, have you seen math.stackoverflow.com. While we are viewing the page it prompts user to update the content saying that there are some posts with updated content. I need to know how to implement that functionality. How to compare the existing content with updated content? Any Ideas? Jul 1, 2013 at 15:10
-
You can use web sockets, i presume. When page loads, a persistent connection opens. When something new is added to the database table with messages (comments, entries etc) the notification is being sent via this connection and so the user sees a message on the page, which tells him about some new content. Or you can just load this new content. At least it is how i solved this problem in my application with comments. I used Rails as a framework and Faye as a solution for setting persistent connection. Socket IO can also do this trick, but i haven't used it :(. Jul 1, 2013 at 15:19