1

I have an application where the application's user relates to an HTML page during the application's runtime.

During runtime, the HTML file is being continuously updated. In order to handle every update, the HTML file is being refreshed at a fixed interval.

Is there any other better way to achieve this with more efficiency and/or to hide the refreshing technique from the user's perspective?

Any help will be greatly appreciated.

brandbir
  • 305
  • 3
  • 14
  • 1
    I guess what youre asking is _AJAX_ – Batu.Khan Apr 18 '14 at 15:59
  • The refreshing is not concerned with the retrieving of data from a server. The HTML code is being updated during runtime..Do you still think that it is manageable by ajax? – brandbir Apr 18 '14 at 16:10
  • Oh. Are you saying the page itself changes? – Batu.Khan Apr 18 '14 at 16:16
  • Yes, the page itself is changing internally (i.e the HTML code is being updated according to the user's action) – brandbir Apr 18 '14 at 16:19
  • Without more info, I would assume you could listen for certain events the user does and update based on completing an event. – tmcc Apr 18 '14 at 19:19
  • It is unclear exactly what you're asking for. Is there something wrong with updating the HTML every time you get more data? Is the issue that the page is flashing, or something? – Sam Fen Apr 18 '14 at 19:23
  • My issue is that since this is a console app in which the user events are handled by the console, the changes must reflect in an HTML file (for reference). So, every update the user makes, the corresponding HTML file is modified. Hence for being able to update the contents from the browser I am currently refreshing the file and therefore the page will flash a little bit.. Is this the only approach that I can take? Thanks – brandbir Apr 18 '14 at 22:50

2 Answers2

0

If what you're doing doesn't involve retrieving data from a server, and instead involves some kind of process that occurs on the page itself, like a clock, I would use setInterval

setInterval(function(){myFunction()},1000);

This would call myFunction() every second, and inside of that function you can change visual elements as appropiate.

You may also want to consider using a Javascript MVC framework such as Backbone.js or Angular.js, which handle changing the appearance of html elements mapped to javascript variables over the lifetime of an application for you.

Seanna
  • 31
  • 3
0

From your question it sounds as if your updating the HTML file on the server in response to user actions. I'm guessing that's not literally what you meant. If it is, though, there are almost certainly better ways to do what you want to do -- depending on what, exactly, it is.

If you are just showing new information to the user, you will want to use Javascript to update the page's DOM. The easiest way for a beginner to do that would be to start by looking at jQuery tutorials. With Javascript (possibly aided by jQuery) you can easily update the content of any part of your page, without needing to actually change the original HTML file in any way.

If you want the page to be updated for everyone who visits it at a later date, then you need to put the new information in a database, and get the content from the database when you the page is requested or loaded.

It would greatly help if you specified exactly what you were trying to do.

Sam Fen
  • 5,074
  • 5
  • 30
  • 56
  • My situation involves system where the user has access to a particular HTML file. Depending on the user behaviour, the HTML file (accessed locally by the user) is altered (exactly as you have mentioned this is obviously being updated by writing jquery to the user's HTML file). So in order for the user to have the recent made changes, I am continously refreshing the file. My question is if there is another better way for this approach (for not keeping refreshing at a fixed interval) or else how to hide the behavior for the user that the file is being refreshed. Hope that this is more clear – brandbir Apr 18 '14 at 22:29
  • I think you are still a little confused. "this is obviously being updated by writing jquery to the user's HTML file". When you use jQuery, you are *not* updating the HTML file itself. You are updating the page's DOM. When you insert a new element, or change some text, the original file doesn't get changed, just the representation that is being displayed on the user's screen. This being the case, you should not need to refresh the page. If I'm mistaken about how you are changing the HTML, can you describe exactly how it is being changed? – Sam Fen Apr 21 '14 at 18:34