Skip to content
Advertisement

Update data on a page without refreshing

I have a website where I need to update a status. Like for a flight, you are departing, cruise or landed. I want to be able to refresh the status without having my viewers to have and reload the whole page. I know there is a way to do it with AJAX and jQuery, but I don’t have any understanding of how that works. I also don’t want them to have and click a button. If anybody knows how that would be done I much appreciate it!

Advertisement

Answer

In general, if you don’t know how something works, look for an example which you can learn from.

For this problem, consider this DEMO

You can see loading content with AJAX is very easily accomplished with jQuery:

JavaScript

Try to understand how this works and then try replicating it. Good luck.

You can find the corresponding tutorial HERE

Update

Right now the following event starts the ajax load function:

JavaScript

You can also do this periodically: How to fire AJAX request Periodically?

JavaScript

I made a demo of this implementation for you HERE. In this demo, every 2 seconds (setTimeout(worker, 2000);) the content is updated.

You can also just load the data immediately:

JavaScript

Which has THIS corresponding demo.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement