I have heard that AJAX is a way to get a page to refresh when a MySQL db has changed. Basically we have a log (that several users at a time could be looking at), when data is submitted it posts to the MySQL db. Instead of having the page auto-refresh every 2 minutes or so, it would be nice if it would just refresh when a change is detected in the db. This would also cut down on the chances that data is missed due to inopportune refreshing/submitting. Pretty much a novice so any help on where to start would be appreciated.

DS

Since it is you who controls the insertion into the database table, coding a listener which would notify or fire the refresh script as soon as insertion request for a particular table comes shouldn't be that difficult. Some other ways would be polling the table in consideration at regular intervals (by using a daemon thread) and firing off the page refresh as you have been doing till now as soon as a change is detected.

When an AJAX request is complete, the connection between the script and the server is closed. The communication dynamics is just like that between the browser and the server.

Once the connection is closed, the server does not know who just asked for whatever resource, so it cannot notify any of its clients of new changes. You would need to do it as you are currently doing, polling/checking periodically for changes to the db.

On another note, the funtionality that you are looking for I have seen it but with applets on the client side and Tomcat web server on the back end. Not sure if you want to pursue that, but that would be the way to go.

Basically you would be creating a "Chat application" where the users only get to chat with your application (as opposed to other users). When the user chats, the server application receives the message and saves it to the db. As soon as the data is saved, the server sends a "chat message" to all the users. Instead of saying "You have new data. Refresh Now", the server would just "push" the updated info to the clients. The client application would "erase" the old data and update with the new data.

Sounds like I need to revamp what I am doing a bit. Thanks for the input.

>>I have heard that AJAX is a way to get a page to refresh when a MySQL db has changed.

Just so we are clear, most likely the statement about was referring to the case where the user submits some changes via AJAX, the server receives the changes, immediately updates the db, makes a query to obtain the updated content, and returns new content from the db, which may include the changes made by other users (possibly one or two milliseconds before the current user's post). But the server responds only to a client at a time. The one that made the request and posted data. Once the client script receives the "updated" data from the server, the script will update the client's interface.

>>I have heard that AJAX is a way to get a page to refresh when a MySQL db has changed.

Just so we are clear, most likely the statement about was referring to the case where the user submits some changes via AJAX, the server receives the changes, immediately updates the db, makes a query to obtain the updated content, and returns new content from the db, which may include the changes made by other users (possibly one or two milliseconds before the current user's post). But the server responds only to a client at a time. The one that made the request and posted data. Once the client script receives the "updated" data from the server, the script will update the client's interface.

Hello,

I'm still new to web development. So if the update input wasn't done by the same side, the best way for a page refreshing was setting an intervals to refresh/reload the page?

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.