Reputation: 13
I am building a weather station that will update the weather in "real-time" to a MySQL Database. To give the feel of "real-time" without taking up a ton of space on my MySQL server, I have my weather station updating a single cell in the MySQL database every few seconds. I would like to set up a way for a website to view this change in realtime without refreshing the page. I have tried researching a lot, but I can't quite find what I am looking for (at least with more of an explanation into the JQuery and how it works). Most answers have partial as people have a lot more experience.
I have a little experience with PHP and MySQL (I have just started learning a couple of months ago). This project is more of a way to learn JQuery and AJAX (along with PHP and MySQL). Frankly, I don't know a ton as I am just starting into programming.
If I could get a bit more of an explanation into how the JQuery works and what files I need to be placing the information in, that would be great (a lot of other similar answers had a separate "server" file and a "client" file in PHP. Do I really need that?).
I just don't know where to begin or what to put in what files. Maybe I need a tutorial? Thanks.
Upvotes: 1
Views: 13750
Reputation: 286
I think what you are looking for is "Push Technology". But, as a beginner like me, I would introduce you to try out "long pulling". Although is not the best method, you can learn how real-time update works.
I suggest you create a normal working AJAX, then use the code below to repeatedly call for updates from the server.
jQuery(document).ready(function () {
interval = setInterval("checkNewUpdate()",4000); //Set interval for accident checking ajax
}
This function basically retrieves information from the database every 4seconds. This method is not so efficient, but I hope would help you to kick start in push technology.
Visit How do I implement basic "Long Polling"? for more information.
Upvotes: 2
Reputation: 116
I suggest you to create a function to check database status, something like count row in the database or something else like that... the return must be simple a data like number , true or false (not a long data) with interval .. and when it change the fetch function will run
Upvotes: 0