I have three computers; Server, Client and Viewer. I am in control of the server and the viewer.

- The user on the
Clientconnects to theServerand is presented with a webpage. - Through a php script the user uploads an image.
- The image is imbedded in some html.
- The
Vieweris a computer totally without user interaction – there is no keyboard. TheVieweris always at all time running a web browser, displaying the picture page.
My problem now is that even though the picture changes on the server disk, the webpage is not updated. How do I refresh the web browser on the viewer, or part of the webpage?
I know html, css, javascript, php and ajax, but apparently not well enough.
There are at least three ways to accomplish this.
Pure HTML
As pointed out by Amitd‘s comment, in “show.html” add the following
<meta>tag to your document’s<head>element:This will automatically refresh the page every 5 seconds. Adjust the value of the
contentattribute to the desired number of seconds.Pure JavaScript:
As pointed out by MeNoMore,
document.location.reload()will refresh the page when you call it.And as pointed out by tpower AJAX requests could be used, but you’d need to write a web service to return a url to the desired image. The JavaScript to do an AJAX request would look something like this:
Other methods:
Finally, to answer your question to tpower‘s answer…
$.ajax()is using jQuery to do the AJAX call. jQuery is a JavaScript library that makes AJAX calls and DOM manipulation a lot simpler. To use the jQuery library, you’d need to include a reference to it in your<head>element (version 1.4.2 used as an example):You could also download the “jquery.min.js” and host it locally instead but that would, of course, only change the url you are loaded the script from.
The AJAX function above, when written using jQuery would look more like this:
As I hope is evident, the jQuery version is much simpler and cleaner. However, given the small scope of your project I don’t know if you’d want to bother with the added overhead of jQuery (not that it’s all that much). Neither do I know if your project requirements allow the possibility of jQuery. I included this example simply to answer your question of what
$.ajax()was.I’m equally sure that there are other methods by which you can accomplish refreshing the image. Personally, if the image url is always changing, I’d use the AJAX route. If the image url is static, I’d probably use the
<meta>refresh tag.